Hi,

The values of OneToOneFields don't appear to remain selected after
creation or update in default forms (such as those used by the admin
interface). I Looked for a bug report but didnt see one. Has anyone
else run into this?

Take the following set of models:

class Thing1(models.Model):
    name = models.CharField(max_length=20)

class Thing2(models.Model):
    name = models.CharField(max_length=20)

class OTOTest(models.Model):
    other = models.OneToOneField('Thing1')

class FKTest(models.Model):
    other = models.ForeignKey('Thing2')


---

Now, creating an OTOTest with a Thing1, and clicking save and continue
editing, will present a form with "-----" selected (not the Thing1
that you just set).

Another test:

from hosts.models import *
from django.forms import ModelForm, model_to_dict

t1 = Thing1.objects.create(name='thing1')
oto = OTOTest.objects.create(other=t1)
class OTOTestForm(ModelForm):
  class Meta:
    model = OTOTest

oto_form = OTOTestForm(instance=oto)
unicode(oto_form)

u'<tr><th><label for="id_other">Other:</label></th><td><select
name="other" id="id_other">\n<option value=""
selected="selected">---------</option>\n<option value="1">Thing1
object</option>\n</select></td></tr>'

(note selected is on the ---- option)

t2 = Thing2.objects.create(name='thing2')
fk = FKTest.objects.create(other=t2)
class FKTestForm(ModelForm):
  class Meta:
    model = FKTest

fk_form = FKTestForm(instance=fk)
unicode(fk_form)

u'<tr><th><label for="id_other">Other:</label></th><td><select
name="other" id="id_other">\n<option value="">---------</option>
\n<option value="1" selected="selected">Thing2 object</option>\n</
select></td></tr>'

(note selected is on the Thing2 object, as expected)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to