#18599: GenericForeignKey field can't be set on init of model
--------------------------------------+------------------------------------
     Reporter:  dpantele              |                    Owner:  nobody
         Type:  Bug                   |                   Status:  new
    Component:  contrib.contenttypes  |                  Version:  1.4
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by dpantele):

 * cc: dpantele (added)


Comment:

 It is very strange that any object which is passed to the constructor is
 thrown away. In FK situation I can do like that:

 {{{
 >>> a = A()
 >>> b = B(fk=a)
 >>> b.fk.save()
 >>> b.fk_id = b.fk.id
 >>> b.save()
 }}}

 In the GFK situation it is not possible for me to save b object if i don't
 pass a. So, I should everywhere pass two references or use an explicit
 notation:

 {{{
 >>> a = A()
 >>> b = B()
 >>> b.gfk = a
 >>> b.gfk.save()
 >>> b.gfk = b.gfk
 >>> b.save()
 }}}

 Of course, it should be possible to keep reference to non-saved object.
 For example, I need to validate object 'b', and if it is not valid, I
 should not save 'a' object at all.

 I see very simple way of solving this problem: we should keep cached
 object not in object instance, but in the field instance.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18599#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to