#23335: Related fields pointing to custom fields that store different values in 
the
database than the python representation do not remember selections
---------------------------+--------------------------------------
     Reporter:  thenewguy  |                    Owner:  nobody
         Type:  Bug        |                   Status:  closed
    Component:  Forms      |                  Version:  1.7-rc-2
     Severity:  Normal     |               Resolution:  needsinfo
     Keywords:             |             Triage Stage:  Unreviewed
    Has patch:  0          |      Needs documentation:  0
  Needs tests:  0          |  Patch needs improvement:  0
Easy pickings:  0          |                    UI/UX:  0
---------------------------+--------------------------------------
Changes (by timgraham):

 * status:  new => closed
 * resolution:   => needsinfo


Comment:

 I think we really need more effort on your part in suggesting a solution
 since the example is quite complex and very specialized. Once again, I
 spent over an hour looking at this and couldn't figure out the exact
 issue.

 Something suspicious that seems related to the problem:
 {{{
 >>> a = BarInt.objects.get()
 >>> a.pk
 -15
 >>> # a.pk is a shortcut for a.id_id
 >>> a.id_id
 -15
 >>> a.id
 <FooInt: 185>

 >>> # how form data is generated
 >>> model_to_dict(a)
 {'id': -15}

 >>> # how form choices are generated
 >>> [str(a) for a in FooInt.objects.all()]
 ['185']
 }}}

 I could make the Id and Fk widgets work by adding this method to the
 model:
 {{{
     def serializable_value(self, field_name):
         val = super(FooInt, self).serializable_value(field_name)
         if field_name == 'id':
             return val.db_value
         return val
 }}}
 but this may not be a good solution and I'm not sure if this will cause
 other problems (also m2m didn't work).

 Also it would be helpful to modify your project so that it doesn't use
 `SubFieldBase` to verify the issue still exists without that (I suspect it
 does).

--
Ticket URL: <https://code.djangoproject.com/ticket/23335#comment:4>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.685a4c1b236e7d30e7dab0e1caa23203%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to