On Sun, May 24, 2009 at 10:53 AM, Viktor <viktor.n...@gmail.com> wrote:

>
> Hi,
>
> I have two models, a parent and a child, and would like to extend an
> already existing parent to have the child attributes as well. I'm
> likely to miss something obvious, but couldn't find it.
>
> class Attendee(models.Model):
>
> and
>
> class Submission(Attendee):
>    attendee = models.OneToOneField(Attendee, parent_link=True)
>
> extends upon Attendee.with a hand-coded backward relation (I'll be
> happy to drop this if my problem can be solved without it)
>
> These work well:
> >>> attendee = models.Attendee.objects.create(user=User.objects.get(pk=1),
> nametag='', conference=conf)
> >>> submit1 = models.Submission.objects.create(user=User.objects.get(pk=1),
> nametag='', conference=conf, title='Title', abstract='Abstract',
> document='no/doc', topic=topic)
>
> but how can I bind an already existing Attendee object to a new
> Submission object? Something along the lines of
>
> >>> submit2 = models.Submission.objects.create(attendee=attendee,
> title='Title', abstract='Abstract', document='no/doc', topic=topic)
> Traceback (most recent call last):
>  File "<console>", line 1, in <module>
>  File "/home/nagyv/virtualenv/django-1.0.2/lib/python2.5/site-
> packages/Django-1.0.2_final-py2.5.egg/django/db/models/manager.py",
> line 99, in create
>    return self.get_query_set().create(**kwargs)
>  File "/home/nagyv/virtualenv/django-1.0.2/lib/python2.5/site-
> packages/Django-1.0.2_final-py2.5.egg/django/db/models/query.py", line
> 319, in create
>    obj.save(force_insert=True)
>  File "/home/nagyv/workspace/MKKE/conference/models.py", line 212, in
> save
>    if not self.topic in self.conference.topic_set.all():
>  File "/home/nagyv/virtualenv/django-1.0.2/lib/python2.5/site-
> packages/Django-1.0.2_final-py2.5.egg/django/db/models/fields/
> related.py", line 235, in __get__
>    raise self.field.rel.to.DoesNotExist
> DoesNotExist
>
> or
>
> >>> submit2 = models.Submission(title='Title', abstract='Abstract',
> document='no/doc', topic=topic)
> >>> submit2.attendee = attendee
> >>> submit2.save()
> Traceback (most recent call last):
>  File "<console>", line 1, in <module>
>  File "/home/nagyv/workspace/MKKE/conference/models.py", line 212, in
> save
>    if not self.topic in self.conference.topic_set.all():
>  File "/home/nagyv/virtualenv/django-1.0.2/lib/python2.5/site-
> packages/Django-1.0.2_final-py2.5.egg/django/db/models/fields/
> related.py", line 235, in __get__
>    raise self.field.rel.to.DoesNotExist
> DoesNotExist
>
> thanks,
> Viktor
> >
>
Take a look at this ticket: http://code.djangoproject.com/ticket/7623 and
possibly the attached patch (I'm not familiar with that patch itself, but
that code looks remarkably similar to some we use where I work).

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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