On Tue, Sep 1, 2009 at 1:20 AM, aa56280 <aa56...@gmail.com> wrote: > > ### Model ### > class School(models.Model): > url = models.SlugField(max_length=50, unique=True) > name = models.CharField(max_length=255) > ... > > > ### Form ### > class SchoolForm(ModelForm): > > class Meta: > model = School > fields = ('url', 'name') > > ### View ### > def new_school(request): > if request.method == 'POST': > form = SchoolForm(request.POST) > if form.is_valid(): > form.save() > > new_school craps out with an IntegrityError exception any time I have > a duplicate value. Any additional thoughts? >
I'd guess something from the snippet that is relevant has been removed. I cannot recreate the problem you are reporting. If I change new_school (just to simplify shell testing) to: def new_school(d): form = SchoolForm(d) if form.is_valid(): form.save() print 'Saved the new school' else: print 'Errors on form validation: %r' % form.errors Then test in the shell: >>> from ttt.models import new_school >>> new_school({'url': 'abcde', 'name': 's1'}) Saved the new school >>> new_school({'url': 'abcde', 'name': 's1'}) Errors on form validation: {'url': [u'School with this Url already exists.']} >>> There is something different about what you are doing, but I don't know what it is. If I were you I'd start with this minimal example and verify it works for you, then add back the things from your actual code that are missing, so as to figure out what additional piece is coming into play here. Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~----------~----~----~----~------~----~------~--~---