Wednesday, October 28, 2015

Re: Django Models Joining and Normalising

Hello,

I'd personally keep it all in one model for as long as possible. It will really simplify queries and it should make your code a lot cleaner. Wait til you have some actual performance problems before splitting the models up.

Collin

On Wednesday, October 14, 2015 at 12:11:55 PM UTC-4, Yunti wrote:
I'm still relatively new to Django and now working on a project that has much more complex models than I've used before.  

The question is about when is it best to separate out large models into separate models (and the impact caused by joining the smaller models together and also keeping data normalised).  

I'm trying to model magazine subscriptions, which are available from different suppliers - the costs vary slightly per region (due to delivery costs) and the available subscriptions vary slightly dependent on payment type (direct debit, card, cheque etc...). 

The subscriptions have a lot of different fields for each subscriptions so I'm not clear on how best to represent this in django - one large model or split into smaller models.

Firstly,  each supplier will have multiple magazines - to keep the data normalised should the suppliers be kept in a separate table/model separate to the subscriptions table? How will this impact performance when having to join the data back together when querying a list of subscriptions. 
(e.g. similarly for payment types of which there are only 4 should these be pulled out into a separate table? and regions)

There will be a form field for: 
supplier
payment type,
region,
should a separate model be made for these 3 fields to ease with making the form and how should that tie into the above tables (if they should be separated? Should I make e.g. an Input model class with ForeignKeys to each of the separate tables?). 

Thanks.  


--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7d7cd8ae-ebd9-43f7-aa8b-ba967dc93795%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment