Friday, May 30, 2014

Re: OneToOne? Inheritance? Another solution for nested model relationships?

I see your point. In this case I'd recommend giving Researcher two foreign keys, one towards a Student model and one towards a Staff one, then add some logic to the model to easily check the actual specialization or to convert it among them. Basically you get a Researcher that "owns" a Student or a Staff role.

Does this fit better? Let me know

Regards,

Leo

Leonardo Giordani
Author of The Digital Cat
My profile on About.me - My GitHub page - My Coderwall profile


2014-05-28 14:37 GMT+02:00 Daniele Procida <daniele@vurt.org>:
On Wed, May 28, 2014, Leonardo Giordani <giordani.leonardo@gmail.com> wrote:

>I usually solve such issues with Inheritance. I feel comfortable with it
>because it lets me (in your example) to manage both ResearchStudent and
>ResearchStaff independently, while keeping the Researcher parent model
>available to deal with "global" queries and data interaction.

It it were a case where abstract inheritance would work, I would agree. Unfortunately, the Researcher model can't be abstract (because it has its own relations with Publications).

If I use multi-table inheritance, that solves part of the problem. However I don't know how well it would work if I have a Researcher, who at some point needs to be a ResearchStudent and maybe later becomes ResearchStaff.

Regards,

Daniele

--
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/20140528123744.1377784185%40smtpauth.cf.ac.uk.
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 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/CAEhE%2BOkKVXb-QKP5KNB003Q%3DrTGxane5vHMAwJETokbq%3D1H87A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment