Advice needed: One big model or many apps with highly interlinked data tables?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Advice needed: One big model or many apps with highly interlinked data tables?

Mikkel Kromann
Hi.

I'm new to Django, and I'm working my way into Django by going through the nice Djangoproject.com turorial.
I'm trying to find out whether Django is the right tool for my task, which is maybe a bit unusual for Django.

My task is to build a web interface to a database for an calculation tool made in Python.
The database will contain maybe up to 100.000 pieces of data (mostly decimal fields), and the tool will import this data, do some calculations and write some results back to the database.

My Django web interface should allow the user to view, add, delete and edit the data in the database, and view the results with tables and charts.
The data is organised in various chunks:

- "Sets" which lend themselves very nicely to Django models, i.e. HouseholdType, Item, City, Month, Year
- "Maps", which are user defined ManyToOne or ManyToMany relations between the various sets (can probably be worked into the "sets" models)
- "Data Tables", which contains the main load of data, having the "sets" as foreign keys (e.g. "Demand" for each HouseholdType, Item, City, Month and year)
- "Results tables", calculated by the tool but in structure quite similar to the "Data tables"

I will have roughly 10 sets, 10 maps. 20-30 data tables and 10-20 result tables.
I understand that putting all these into a one app will create biiig models.py and views.py files, which is probably a bad idea.

On the other hand, splitting the sets, maps and tables into several apps does not seem to be an ideal solution either.
All the tables and the maps will be models that have foreign keys to the "sets" models.
My understanding so far is, that it is also bad to have a lot of interlinkage between the various apps.

An intermediate solution might be, that if I make a "Sets" app containing all the models that are going to be primary key in the other apps, then the interlinkages between the apps is somewhat simplified.

Any thoughts or advice?


cheers, Mikkel


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7b0f436c-4bef-4c1f-b513-e18b820fb570%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed: One big model or many apps with highly interlinked data tables?

shubham jhandei
Hi Mikkel,

I have used Django long back, so it might not be the best solution. 

Surely creating one big models.py and views.py will make your code not scalable for future, and making small interlinked apps will also not the best idea. 

Your intermediate solution is better than both above solutions. One optimisation you can do it try to make a dependency graph, and create apps with most interlinked cluster. May be every cluster will have a "Sets" model, or a separate app depending upon the graph you will create.

So I will suggest to create a graph, and see what can be the best solution you can have.  

Regards,
Shubham Jhandei

On Saturday, April 14, 2018 at 7:40:27 PM UTC+5:30, Mikkel Kromann wrote:
Hi.

I'm new to Django, and I'm working my way into Django by going through the nice Djangoproject.com turorial.
I'm trying to find out whether Django is the right tool for my task, which is maybe a bit unusual for Django.

My task is to build a web interface to a database for an calculation tool made in Python.
The database will contain maybe up to 100.000 pieces of data (mostly decimal fields), and the tool will import this data, do some calculations and write some results back to the database.

My Django web interface should allow the user to view, add, delete and edit the data in the database, and view the results with tables and charts.
The data is organised in various chunks:

- "Sets" which lend themselves very nicely to Django models, i.e. HouseholdType, Item, City, Month, Year
- "Maps", which are user defined ManyToOne or ManyToMany relations between the various sets (can probably be worked into the "sets" models)
- "Data Tables", which contains the main load of data, having the "sets" as foreign keys (e.g. "Demand" for each HouseholdType, Item, City, Month and year)
- "Results tables", calculated by the tool but in structure quite similar to the "Data tables"

I will have roughly 10 sets, 10 maps. 20-30 data tables and 10-20 result tables.
I understand that putting all these into a one app will create biiig models.py and views.py files, which is probably a bad idea.

On the other hand, splitting the sets, maps and tables into several apps does not seem to be an ideal solution either.
All the tables and the maps will be models that have foreign keys to the "sets" models.
My understanding so far is, that it is also bad to have a lot of interlinkage between the various apps.

An intermediate solution might be, that if I make a "Sets" app containing all the models that are going to be primary key in the other apps, then the interlinkages between the apps is somewhat simplified.

Any thoughts or advice?


cheers, Mikkel


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/71e6d05b-20c7-46cc-a59e-1815f539aaf6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed: One big model or many apps with highly interlinked data tables?

PASCUAL Eric
In reply to this post by Mikkel Kromann

Hi Mikkel,


When facing this type of situation, I tend to use one of these two options, depending on the number of model classes:


  • if the number of classes is reasonable, I use a single app, but implement the models in a model package, distributing the classes into modules inside this package so that each one is reasonable in size and packs together closely related classes. Same for the views BTW.
  • if this would not be enough, I break the global app into smaller ones, trying to map the "business domains" of the application. The guideline here is that the dependencies between domains should be kept as reduced as possible. A side effect of this approach is that it can happen that some of the apps are generic enough to be reusable in other Django projects.


I don't pretend that this is the "official" way to proceed. Maybe there are smarter way to do.


Best regards


Eric PASCUAL

Centre Scientifique et Technique du Bâtiment
290 route des Lucioles - BP 209
06904 SOPHIA ANTIPOLIS CEDEX
http://www.cstb.fr


From: [hidden email] <[hidden email]> on behalf of Mikkel Kromann <[hidden email]>
Sent: Saturday, April 14, 2018 3:52:38 PM
To: Django users
Subject: Advice needed: One big model or many apps with highly interlinked data tables?
 
Hi.

I'm new to Django, and I'm working my way into Django by going through the nice Djangoproject.com turorial.
I'm trying to find out whether Django is the right tool for my task, which is maybe a bit unusual for Django.

My task is to build a web interface to a database for an calculation tool made in Python.
The database will contain maybe up to 100.000 pieces of data (mostly decimal fields), and the tool will import this data, do some calculations and write some results back to the database.

My Django web interface should allow the user to view, add, delete and edit the data in the database, and view the results with tables and charts.
The data is organised in various chunks:

- "Sets" which lend themselves very nicely to Django models, i.e. HouseholdType, Item, City, Month, Year
- "Maps", which are user defined ManyToOne or ManyToMany relations between the various sets (can probably be worked into the "sets" models)
- "Data Tables", which contains the main load of data, having the "sets" as foreign keys (e.g. "Demand" for each HouseholdType, Item, City, Month and year)
- "Results tables", calculated by the tool but in structure quite similar to the "Data tables"

I will have roughly 10 sets, 10 maps. 20-30 data tables and 10-20 result tables.
I understand that putting all these into a one app will create biiig models.py and views.py files, which is probably a bad idea.

On the other hand, splitting the sets, maps and tables into several apps does not seem to be an ideal solution either.
All the tables and the maps will be models that have foreign keys to the "sets" models.
My understanding so far is, that it is also bad to have a lot of interlinkage between the various apps.

An intermediate solution might be, that if I make a "Sets" app containing all the models that are going to be primary key in the other apps, then the interlinkages between the apps is somewhat simplified.

Any thoughts or advice?


cheers, Mikkel


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7b0f436c-4bef-4c1f-b513-e18b820fb570%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/DB7P193MB0331DEFE1ECAFCE751BE57FD8CB70%40DB7P193MB0331.EURP193.PROD.OUTLOOK.COM.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Advice needed: One big model or many apps with highly interlinked data tables?

Mike Dewhirst-3
In reply to this post by Mikkel Kromann
Don't forget that you can also split all your model classes one each into their own separate files. Create a models dir and put them in there.

Then in app/models/__init__.py you say ...

from .thismodel import ThisModel
from .thatmodel import ThatModel

And so on.

In any view or other file you can then say ...

from app.models import ThisModel

Or

from .models import ThatModel

... just as though it was in a single models.py

Let's you easily manage many models in a single app.

You do have to manage the individual class imports but that is more explicit and therefore more pythonic ;)

Cheers

Mike

Connected by Motorola


PASCUAL Eric <[hidden email]> wrote:

Hi Mikkel,


When facing this type of situation, I tend to use one of these two options, depending on the number of model classes:


  • if the number of classes is reasonable, I use a single app, but implement the models in a model package, distributing the classes into modules inside this package so that each one is reasonable in size and packs together closely related classes. Same for the views BTW.
  • if this would not be enough, I break the global app into smaller ones, trying to map the "business domains" of the application. The guideline here is that the dependencies between domains should be kept as reduced as possible. A side effect of this approach is that it can happen that some of the apps are generic enough to be reusable in other Django projects.


I don't pretend that this is the "official" way to proceed. Maybe there are smarter way to do.


Best regards


Eric PASCUAL

Centre Scientifique et Technique du Bâtiment
290 route des Lucioles - BP 209
06904 SOPHIA ANTIPOLIS CEDEX
http://www.cstb.fr


From: [hidden email] <[hidden email]> on behalf of Mikkel Kromann <[hidden email]>
Sent: Saturday, April 14, 2018 3:52:38 PM
To: Django users
Subject: Advice needed: One big model or many apps with highly interlinked data tables?
 
Hi.

I'm new to Django, and I'm working my way into Django by going through the nice Djangoproject.com turorial.
I'm trying to find out whether Django is the right tool for my task, which is maybe a bit unusual for Django.

My task is to build a web interface to a database for an calculation tool made in Python.
The database will contain maybe up to 100.000 pieces of data (mostly decimal fields), and the tool will import this data, do some calculations and write some results back to the database.

My Django web interface should allow the user to view, add, delete and edit the data in the database, and view the results with tables and charts.
The data is organised in various chunks:

- "Sets" which lend themselves very nicely to Django models, i.e. HouseholdType, Item, City, Month, Year
- "Maps", which are user defined ManyToOne or ManyToMany relations between the various sets (can probably be worked into the "sets" models)
- "Data Tables", which contains the main load of data, having the "sets" as foreign keys (e.g. "Demand" for each HouseholdType, Item, City, Month and year)
- "Results tables", calculated by the tool but in structure quite similar to the "Data tables"

I will have roughly 10 sets, 10 maps. 20-30 data tables and 10-20 result tables.
I understand that putting all these into a one app will create biiig models.py and views.py files, which is probably a bad idea.

On the other hand, splitting the sets, maps and tables into several apps does not seem to be an ideal solution either.
All the tables and the maps will be models that have foreign keys to the "sets" models.
My understanding so far is, that it is also bad to have a lot of interlinkage between the various apps.

An intermediate solution might be, that if I make a "Sets" app containing all the models that are going to be primary key in the other apps, then the interlinkages between the apps is somewhat simplified.

Any thoughts or advice?


cheers, Mikkel


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7b0f436c-4bef-4c1f-b513-e18b820fb570%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2qxrso5rfybp9kie2odxw2ha.1523970349218%40email.android.com.
For more options, visit https://groups.google.com/d/optout.