On Tue, Apr 19, 2011 at 7:28 PM, Jacob Kaplan-Moss <ja...@jacobian.org>wrote:

> 2011/4/19 Juan Pablo Romero Méndez <jpablo.rom...@gmail.com>:
> > Is it possible to create unidirectional relations within django's orm?
> >
> > What I mean is a situation where a parent has a children_set of
> > references to children, but the children don't have any reference to
> > the father.
>
> See the documentation for ForeignKey.related_name:
>
> http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.related_name
> .
> In particular, note the part about what `related_name="+"` does.
>

Jacob,
That sounds like it would create exactly the opposite situation from what is
wanted.

class Parent(models.Model):
    pass
class Child(models.Model):
    parent = models.ForeignKey(Parent, related_name='+')

would give a child a reference to their parent, without the parent having a
child_set attribute.

I think Mike has the right idea; using a separate 1:many table to avoid
explicit fields on the child model, but, of course, SQL being what it is, it
is still possible to construct a query that joins the tables and
reconstructs the link from child to parent.

-- 
Regards,
Ian Clelland
<clell...@gmail.com>

-- 
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