The problem ("Foo bar with this None and None already exists.") only
happens when I use a ModelForm and choose to specify the field details
myself. Here is an example

Models

class Foo(models.Model):
    f = models.IntegerField(unique=True)
    def __unicode__(self):
        return 'Foo with f = %d' % self.f

class Bar(models.Model):
    b = models.IntegerField(unique=True)
    def __unicode__(self):
        return 'Bar with b = %d' % self.b

class FooBar(models.Model):
   foo = models.ForeignKey('Foo')
   bar = models.ForeignKey('Bar')

   class Meta:
       unique_together = (('foo','bar'),)


Form

class FooBarForm(forms.ModelForm):
    foo = forms.ModelChoiceField(Foo.objects.all())
    bar = forms.ModelChoiceField(Bar.objects.all())

    class Meta:
        model = FooBar


Try to save a combination of foo and bar that already exists and the
error message says "this None and None", comment out the field
overrides and there's no problem. I have had a look at the ModelForm
and the unique_together code but didn't find anything.

--

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


Reply via email to