Daniele,

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.

As always with inheritance, I suggest to think twice before implementing
it, but in this case I'd say that it fits perfectly.


Regards,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2014-05-26 23:33 GMT+02:00 Daniele Procida <dani...@vurt.org>:

> I've an application that's been happily running for a few years, that does
> this:
>
> class Person(Model):
>    # everyone's a Person
>
> class Researcher(Model):
>     # a Researcher is Person who publishes research
>     person = models.OneToOneField(Person)
>
> class Publication(Model):
>     author = models.ForeignKey(Researcher)
>
>
> But this is no longer enough: now I also need to distinguish between
> Researchers who are research students and members of staff. Those who are
> students will need new fields such as "thesis_title" and "supervisors".
>
> But, I will *still* need the Researcher class independently of the new
> ResearchStudent and ResearchStaff classes, because it's needed for
> Publication.author.
>
> So now it might look something like this:
>
> class Person(Model):
>    # everyone's a Person
>
> class Researcher(Model):
>     # a Researcher is Person who publishes research
>     person = models.OneToOneField(Person)
>
> class ResearchStaff(Model):
>    researcher = models.OneToOneField(Researcher)
>
> class ResearchStudent(Model):
>    researcher = models.OneToOneField(Researcher)
>    supervisors = models.ManyToManyField(ResearchStaff)
>
> class Publication(Model):
>     author = models.ForeignKey(Researcher)
>
>
> How manageable is this going to be? Is there a better way of doing what I
> need to do, perhaps through inheritance?
>
> Thanks,
>
> 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+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/20140526213320.1042853662%40mail.wservices.ch
> .
> 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+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/CAEhE%2BOkbUadKLYPqjqqLFAkdrBY86Lyjv_AoYG%3Dd8fY6A6WdnQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to