Hi Tom,

Am 2013-04-25 18:53, schrieb Tom Evans:
Yes, this is correct, when you assign an object to a foreign key, it
must already be saved so that it has an id in order to persist in the
database.

It's very good to hear this, thank you very much for your reply!

In 1.4, the check is not present:
https://github.com/django/django/blob/stable/1.4.x/django/db/models/fields/related.py#L259
So I guess you're using 1.4!

No, I'm using 1.5.1 (sorry for not having mentioned this earlier), but didn't get any exception, exactly as shown in my original mail.

Thanks to your pointers into the code, I tested a bit more, and it seems that my case is not handled in class SingleRelatedObjectDescriptor, but in class ReverseSingleRelatedObjectDescriptor -- which I don't understand, but can easily trigger the assertion in line

https://github.com/django/django/blob/1.5.1/django/db/models/fields/related.py#L405

by a statement like   ma.vbp = SomeOtherClass()

The __set__ method in ReverseSingleRelatedObjectDescriptor does not seem to have an equivalent to the check in SingleRelatedObjectDescriptor, so this explains why I could do the original assignment ma.vbp = Vorblendplan()

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


Reply via email to