Hi Alex,

I've written previously about encapsulation and Django models 
<http://www.dabapps.com/blog/django-models-and-encapsulation/>, and I think 
that's kinda relevant here.
If you apply the policy "never write to a model or call .save() directly" 
then yes, you can ensure that the only access points
for modifying the state of eg 'line items', is eg the owning 'order' 
instance.

In some cases there may not be an order instance as such (eg if you simply 
have an order id against the line items, but no fully fledged 'order' table 
in your database) in which case you'd apply the encapsulation either in the 
LineItem manager class, or in a helper class that represents and interacts 
with orders, but does not map directly to a database table itself.

A final consideration here is that these sorts of case *might* map well to 
cases where you want an element of document-structure in your data models, 
rather than relational  structure. (eg. a JSON field against the order that 
stores line item data) that call depends on what information you're going 
to need to index aggregate etc. Probably not what you need, but worth 
mentioning as an option.

Hope that helps give some food for thought.


  T.

-- 
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+unsubscr...@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/e390b879-21c3-4f93-935c-768d4b89ae8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to