Thursday, April 25, 2013

Re: Problem with creating a one-to-one instance

Hi all,

Am 16.04.2013 17:50, schrieb Carsten Fuchs:
> I'm probably overlooking something very simple, but still cannot explain
> what the code below does wrong: [...]
>
> >>> ma = Mitarbeiter.objects.get(key="F426")
> >>> ma.vbp # ok, initially "None"
> >>> ma.vbp = Vorblendplan()
> >>> ma.vbp.save()
> >>> ma.save()
>
> >>> ma = Mitarbeiter.objects.get(key="F426")
> >>> ma.vbp # Why still "None"??

I guess it's because the assignment

ma.vbp = Vorblendplan()

also updates ma.vbp_id (None), and is not updated in the subsequent

ma.vbp.save()

so that subsequently:

>>> ma.vbp.id
4741
>>> ma.vbp_id
# Still None


In the example that works (in my original mail, not quoted here), when
the assignment is done, the Vorblendplan instance already has an id, so
that it is properly carried into ma.vbp_id.

Can someone confirm this, is my understanding correct?

Best regards,
Carsten

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment