class Address(models.Model):
person = models.ForeignKey(Person)
contact_type = models.ForeignKey(ContactType)
name = models.CharField(blank=True, maxlength=80)
line1 = models.CharField(blank=True, maxlength=80)
line2 = models.CharField(blank=True, maxlength=120)
city = models.CharField(blank=True, maxlength=80)
state = models.CharField(blank=True, maxlength=80)
zip = models.CharField(blank=True, maxlength=80)
country = models.ForeignKey('CountryInfo', null=True, blank=True, db_column='country')
timestamp = models.DateTimeField(auto_now=True)
invalid = models.BooleanField(default=0)
merged_from = models.IntegerField(null=True, blank=True)
Python 2.4.3 (#2, Oct 6 2006, 07:52:30)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from fsforg.amt import models as amt
>>> from django import newforms as forms
>>> AddressForm = forms.form_for_model(amt.Address)
>>> jag = amt.Person.objects.get(username='jag')
>>> jag_addy = jag.address_set.all().values()[0]
>>> form = AddressForm(jag_addy)
>>> print form['country']
Traceback (most recent call last):
File "<console>", line 1, in ?
File "/usr/lib/python2.4/site-packages/django/utils/encoding.py", line 31, in __str__
return self.__unicode__().encode(settings.DEFAULT_CHARSET)
File "/usr/lib/python2.4/site-packages/django/newforms/forms.py", line 238, in __unicode__
value = self.as_widget(self.field.widget)
File "/usr/lib/python2.4/site-packages/django/newforms/forms.py", line 265, in as_widget
return widget.render(self.html_name, data, attrs=attrs)
File "/usr/lib/python2.4/site-packages/django/newforms/widgets.py", line 170, in render
for option_value, option_label in chain(self.choices, choices):
File "/usr/lib/python2.4/site-packages/django/newforms/models.py", line 126, in __iter__
yield (obj._get_pk_val(), str(obj))
TypeError: __str__ returned non-string (type NoneType)
>>> jag_addy['country_id']
'US'