On Wednesday, January 26, 2011 11:41:10 AM UTC, aid wrote:
>
>
> Hi,
>
> I'm creating a DB using Django for managing our companies data - customers, 
> services, orders, billing etc.  I'm using the Django admin interface to 
> manage the data.
>
> I seem to be consistently at odds with myself and would be good to hear the 
> community's point of view on this.
>
> I'm defining the DB in Python; using objects and inheritance.  As such, 
> when I'm doing this I'm thinking in an object orientated (OO) manner - a 
> service uses a number of resources so I create a Service object with with 
> either foreign key or many-to-many (as appropriate) relationship to the 
> Resource objects.  This gives me nice referential integrity and I can be 
> sure that the Service has valid connections to the Resources it requires.
>
> It seems, however, that Django expects the models not to be defined in an 
> OO manner.  For example; should I wish resources to be listed as Inlines on 
> the Service's page  I can only do this if the foreign key is with the 
> Resource - pointing 'up' the stack to the services - as possible to being 
> pointed to by the Service.  Django seems to be defining stricture using an 
> OO language; but expecting that structure in a more traditional, relational 
> database, style where entries point up to their owners rather than the 
> owners pointing down to their children.
>
> In order to try to fit in with Django Admin I've ended up using both 
> styles.  Unsurprisingly this mixture of styles is now causing me problems 
> with circular dependencies.  I know I need to jump one way or the other; but 
> would be great to get some comments from experienced Django coders before I 
> decide which way...
>
> Any comments/advice welcome...
>
> Cheers,
>
> aid
>

This is what's known as the object-relational impedance mismatch [1]. 
Unfortunately, as you've noticed, OO concepts don't map completely cleanly 
onto the relational model, and this is an issue with all systems that 
attempt to do it. Django does what it can to smooth over the gaps, but can't 
always do everything.

However, you should not be getting circular dependencies. Can you provide 
some examples? One place where I often see them is when two models in 
separate applications are related via ForeignKey, and the developer has 
imported each model into the other's models.py. But it isn't necessary to 
import them at all, as you can refer to models via strings: 

    myfkfield = models.ForeignKey('otherapp.OtherModel')

so no circular dependency is declared. Does that solve your problem? If not, 
some examples will be helpful.
--
DR.

[1] wikipedia has a good 
write-up: http://en.wikipedia.org/wiki/Object-relational_impedance_mismatch

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to