Re: m2m symmetry confusion
On 12 April 2013 10:47, Matt Schinckelwrote: > > But a partner relationship is not at all related to a parent-child > relationship. Ah! But if you look at my original spec, I had the desire to track partners - I know it's not part of the parent-child relationship, but I did have the desire to track it. Having said that, I've given it some thought, and I don't think I need to track the partnerships anymore :) > Person > - date-of-birth > - date-of-death > - mother (fk-> Person) > - father (fk -> Person) > - adoptive_parent (m2m -> Person, maybe use a through table > to get start and finish dates). I think having the fields mother and father is too prescriptive. I'm going to stick with just having a single parent (m2m->person) field. > Or, you could use the parent m2m with a through table to add > the relevant data. birth/adoptive parent, etc. > > And, the partner m2m could also use a through table to store > start and finish times of the relationship. > > Family relationships are hard... Sure Are! -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: m2m symmetry confusion
Conceptually all there is in families is people objects and relationship objects. Therefore, you really only need two tables being person and relationship. This could be satisfied with relationship being the 'through' table for person having m2m('self'). You would probably need a clean() method in the person model which raised an appropriate Exception when someone tried something incestuous :) Sorry about top-posting. Mike On 12/04/2013 10:47am, Matt Schinckel wrote: On Friday, April 12, 2013 9:52:10 AM UTC+9:30, Lachlan Musicman wrote: On 12 April 2013 08:43, Dennis Lee Bieberwrote: On Thu, 11 Apr 2013 16:41:37 +1000, Lachlan Musicman declaimed the following in gmane.comp.python.django.user: An individual typically only has two parents (unless you are considering birth and adoption, which may be needed to handle some of the odd situations forming with the various "same sex marriage" models), so many-to-many isn't really appropriate. And an individual could have many children. So I'd have a pair of links for father mother and that is IT... Children and Siblings are all query results (children of X are those with the appropriate parent slot = X). I like your reasoning, but I disagree on your result. First, it doesn't relate partners, second, it presumes two parents (I am a step father). But a partner relationship is not at all related to a parent-child relationship. That is, you may have children with a person who is not your partner. And, you may have a partner and not have children. And, you may have more than one partner (depending upon where you are, you may have more than one partner simultaneously). If you will only store adoptive OR birth parents, then you can get away with a single mother and father fields. But, even for adoptive relationships, you probably need a start date (and possibly a finish date), so I think they should be stored seperately. Thus, you have: Person - date-of-birth - date-of-death - mother (fk-> Person) - father (fk -> Person) - adoptive_parent (m2m -> Person, maybe use a through table to get start and finish dates). The issue you have then is that you have two fks to Parent, which means you would have to query differently to get a father's children to a mother's. Or you could wrap '.children()' to get the value. So I think I'm going to go with a parent m2m partner m2m and take your advise to trash sibling and children. Back to the grindstone then. Or, you could use the parent m2m with a through table to add the relevant data. birth/adoptive parent, etc. And, the partner m2m could also use a through table to store start and finish times of the relationship. Family relationships are hard... Matt. -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: m2m symmetry confusion
On Friday, April 12, 2013 9:52:10 AM UTC+9:30, Lachlan Musicman wrote: > > On 12 April 2013 08:43, Dennis Lee Bieber> wrote: > > On Thu, 11 Apr 2013 16:41:37 +1000, Lachlan Musicman > > > > > declaimed the following in gmane.comp.python.django.user: > > > > An individual typically only has two parents (unless you are > > considering birth and adoption, which may be needed to handle some of > > the odd situations forming with the various "same sex marriage" models), > > so many-to-many isn't really appropriate. And an individual could have > > many children. > > > > So I'd have a pair of links for > > > > father > > mother > > > > and that is IT... Children and Siblings are all query results (children > > of X are those with the appropriate parent slot = X). > > > I like your reasoning, but I disagree on your result. First, it > doesn't relate partners, second, it presumes two parents (I am a step > father). > But a partner relationship is not at all related to a parent-child relationship. That is, you may have children with a person who is not your partner. And, you may have a partner and not have children. And, you may have more than one partner (depending upon where you are, you may have more than one partner simultaneously). If you will only store adoptive OR birth parents, then you can get away with a single mother and father fields. But, even for adoptive relationships, you probably need a start date (and possibly a finish date), so I think they should be stored seperately. Thus, you have: Person - date-of-birth - date-of-death - mother (fk-> Person) - father (fk -> Person) - adoptive_parent (m2m -> Person, maybe use a through table to get start and finish dates). The issue you have then is that you have two fks to Parent, which means you would have to query differently to get a father's children to a mother's. Or you could wrap '.children()' to get the value. > So I think I'm going to go with a > > parent m2m > partner m2m > > and take your advise to trash sibling and children. > > Back to the grindstone then. > > Or, you could use the parent m2m with a through table to add the relevant data. birth/adoptive parent, etc. And, the partner m2m could also use a through table to store start and finish times of the relationship. Family relationships are hard... Matt. -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: m2m symmetry confusion
On 12 April 2013 08:43, Dennis Lee Bieberwrote: > On Thu, 11 Apr 2013 16:41:37 +1000, Lachlan Musicman > declaimed the following in gmane.comp.python.django.user: > >> # Relations >> parents = models.ManyToManyField("self", related_name='p', >> verbose_name="Parents", null=True, blank=True) >> siblings = models.ManyToManyField("self", related_name='s', >> verbose_name="Siblings", null=True, blank=True) >> partners = models.ManyToManyField("self", related_name='ps', >> verbose_name="Partners", null=True, blank=True) >> children = models.ManyToManyField("self", related_name='c', >> verbose_name="Children", null=True, blank=True) >> > Too many links... > > By definition, full siblings are the set in which all the parents > are identical, so you shouldn't be storing a many-to-many table for > siblings; "step" siblings are the set in which one parent but not the > other are identical. > > An individual typically only has two parents (unless you are > considering birth and adoption, which may be needed to handle some of > the odd situations forming with the various "same sex marriage" models), > so many-to-many isn't really appropriate. And an individual could have > many children. > > So I'd have a pair of links for > > father > mother > > and that is IT... Children and Siblings are all query results (children > of X are those with the appropriate parent slot = X). I like your reasoning, but I disagree on your result. First, it doesn't relate partners, second, it presumes two parents (I am a step father). So I think I'm going to go with a parent m2m partner m2m and take your advise to trash sibling and children. Back to the grindstone then. cheers L. -- The new creativity is pointing, not making. Likewise, in the future, the best writers will be the best information managers. http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: m2m symmetry confusion
Sanjay! On 11 April 2013 18:00, Sanjay Bhangarwrote: > Lachlan, > > Not sure if I grokked your problem exactly, but just from personal > experience when I found my brain turned to jelly with a similar-sounding > issue before, I believe I found the answer in the "symmetrical=False" option > .. I do believe setting symmetrical=False for your 'parents' and 'children' > fields maybe a good first step toward figuring this out -- I did find that > automatic creation of symmetrical relations in this case to be a bit > confusing if you aren't expecting it. And, also, just thinking about it -- > do you actually need two separate fields for parents and children? Why not > just -- > > children = models.ManyToManyField("self", related_name='parents', > verbose_name="Children", symmetrical=False, null=True, blank=True) Good point - although potentially Mike's answer is good too - to have a through table that describes each relationship ...But now that I think about it, I don't want to store any more information about the relationship, so potentially Mike's solution is too broad/abstract. > Tbh, still not sure why your above example did not work: bob = Account(first_name="bob",last_name="sanders",gender='M') sarah = Account(first_name="sarah",last_name="sanders",gender='F') bob.siblings.add(sarah) > > This is not something silly like needing to call bob.save() and sarah.save() > before adding the m2m, is it ? Ah, yes. That was it. "Buggrit, buggrem, see if i don't! Millenium hand and shrimp!" cheers L. -- The new creativity is pointing, not making. Likewise, in the future, the best writers will be the best information managers. http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: m2m symmetry confusion
Mike, thanks for your reply. On 11 April 2013 17:55, Mike Dewhirstwrote: > On 11/04/2013 4:41pm, Lachlan Musicman wrote: >> >> At the moment I have tables on the database: >> >> account_account >> account_account_parents >> account_account_children >> account_account_partners >> account_account_siblings >> > > Not wishing to throw a spanner in the works, but I have always had a design > in the back of my mind for such a set of relationships. > > I think it needs a single table for all the people and a through table > carrying sufficient information to accurately describe each relationship. > This would deliver flexibility to describe any possible relationship > including client, supplier, apprentice etc. You might be right. Those tables are created when I sync - it's not been a design decision I made, I tried a couple of methods and found the mieows was the one that seemed to make the most sense. > I don't think it would be as complex as a multi-table design like yours but > that would depend on what your system has to achieve. What you say is true, although it would be hard to get the reverse relationships with random relationships - how does a through table parenting relationship know that it's reverse is a child relationship? For instance. Oh, I guess it doesn't matter, that's done via related_name et al. Good idea. Have you done any work on it at all? L. -- The new creativity is pointing, not making. Likewise, in the future, the best writers will be the best information managers. http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: m2m symmetry confusion
Lachlan, Not sure if I grokked your problem exactly, but just from personal experience when I found my brain turned to jelly with a similar-sounding issue before, I believe I found the answer in the "symmetrical=False" option .. I do believe setting symmetrical=False for your 'parents' and 'children' fields maybe a good first step toward figuring this out -- I did find that automatic creation of symmetrical relations in this case to be a bit confusing if you aren't expecting it. And, also, just thinking about it -- do you actually need two separate fields for parents and children? Why not just -- children = models.ManyToManyField("self", related_name='parents', verbose_name="Children", symmetrical=False, null=True, blank=True) Tbh, still not sure why your above example did not work: >>> bob = Account(first_name="bob",last_name="sanders",gender='M') >>> sarah = Account(first_name="sarah",last_name="sanders",gender='F') >>> bob.siblings.add(sarah) This is not something silly like needing to call bob.save() and sarah.save() before adding the m2m, is it ? Any-how, um, not sure if that helps at all or adds to the confusion, just that I remember experiencing some brain-jelly and at that point, grokking the 'symmetrical=False' option was my way out of it .. not sure if that's your problem, though :-) Cheers and all the best, Sanjay On Thu, Apr 11, 2013 at 12:31 PM, Lachlan Musicmanwrote: > I tried reading the code in django/db/models/fields/related.py but > quickly realised it was beyond me groking in a half hour. > > BUT, for some reason I felt compelled to test through the admin > interface and it is working. ie, I can create and remove siblings and > partners from each other, error free (seemingly, anyway). > > So, confusion level ++ > > L. > > -- > The new creativity is pointing, not making. Likewise, in the future, > the best writers will be the best information managers. > > > http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith > > -- > 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?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: m2m symmetry confusion
On 11/04/2013 4:41pm, Lachlan Musicman wrote: At the moment I have tables on the database: account_account account_account_parents account_account_children account_account_partners account_account_siblings Not wishing to throw a spanner in the works, but I have always had a design in the back of my mind for such a set of relationships. I think it needs a single table for all the people and a through table carrying sufficient information to accurately describe each relationship. This would deliver flexibility to describe any possible relationship including client, supplier, apprentice etc. I don't think it would be as complex as a multi-table design like yours but that would depend on what your system has to achieve. Mike -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: m2m symmetry confusion
I tried reading the code in django/db/models/fields/related.py but quickly realised it was beyond me groking in a half hour. BUT, for some reason I felt compelled to test through the admin interface and it is working. ie, I can create and remove siblings and partners from each other, error free (seemingly, anyway). So, confusion level ++ L. -- The new creativity is pointing, not making. Likewise, in the future, the best writers will be the best information managers. http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: m2m symmetry confusion
On 11 April 2013 16:19, Lachlan Musicmanwrote: > Hi, > > I'm trying to implement a simple family tree type structure. I'm > expanding on this example code base: > > https://github.com/mieows/familytree-django/blob/master/models.py > > (please ignore any errors in that models.py, I've addressed many of them) > > Ok, simply I have: > > class Account(models.Model) Gah, sorry. class Account(models.Model): user = models.OneToOneField(User, blank=True, null=True) first_name = models.CharField(max_length=60) last_name = models.CharField(max_length=60) # Relations parents = models.ManyToManyField("self", related_name='p', verbose_name="Parents", null=True, blank=True) siblings = models.ManyToManyField("self", related_name='s', verbose_name="Siblings", null=True, blank=True) partners = models.ManyToManyField("self", related_name='ps', verbose_name="Partners", null=True, blank=True) children = models.ManyToManyField("self", related_name='c', verbose_name="Children", null=True, blank=True) So, in Relations we have two type of relationships, symmetrical and non symmetrical. ie: parents<->children is non symmetrical partners<->partner is symmetrical siblings<->siblings is symmetrical Here's where the confusion comes in. As per the original code base I have used the m2m_changed to make sure the adjustments are reflected. With the Parent<->children this has worked as I expected ( jack.parents.add(jill) also reflects that jack is in jill.children.all() ) But with the other two relationships, the m2m_changed are not working. Since both testing and m2m_changed/signals are new to me, my brain is melting a little. 1. a) Should I explicitly have symmetrical=FALSE in the parents/children relationships? ie: parents = models.ManyToManyField("self", symmetrical=FALSE, related_name='p', verbose_name="Parents", null=True, blank=True) siblings = models.ManyToManyField("self", symmetrical=FALSE, related_name='s', verbose_name="Siblings", null=True, blank=True) 1. b) what effect would that have? At the moment I have tables on the database: account_account account_account_parents account_account_children account_account_partners account_account_siblings 2. I am trying to test the reflected removals of partners and siblings and the tests are failing. So I moved to the shell, and I'm seeing this: >>> bob = Account(first_name="bob",last_name="sanders",gender='M') >>> sarah = Account(first_name="sarah",last_name="sanders",gender='F') >>> bob.siblings.add(sarah) Traceback (most recent call last): File "", line 1, in File "/home/datakid/.virtualenvs/kids/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 897, in __get__ through=self.field.rel.through, File "/home/datakid/.virtualenvs/kids/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 586, in __init__ (instance, source_field_name)) ValueError: "" needs to have a value for field "from_account" before this many-to-many relationship can be used. >>> That's where my mind went to jelly. I can see that the error message contains a generated string - "from_account" - but I don't see anything in the docs that would talk about from_CLASS settings. What am I doing wrong? Is it that I've not added the + to related_name? Is it that I've using m2m_changed on a symmetrical relationship (I've just commented out the m2m_changed sibling code and tried again, but it fails with the same message). Confused. cheers L. -- The new creativity is pointing, not making. Likewise, in the future, the best writers will be the best information managers. http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
m2m symmetry confusion
Hi, I'm trying to implement a simple family tree type structure. I'm expanding on this example code base: https://github.com/mieows/familytree-django/blob/master/models.py (please ignore any errors in that models.py, I've addressed many of them) Ok, simply I have: class Account(models.Model) -- The new creativity is pointing, not making. Likewise, in the future, the best writers will be the best information managers. http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.