Hello Kenneth, Yes it would. If the user tries to submit a Change that is not unique on 'student' and 'date' , I want to return them back to the original page with a message that says "You've already got a change submitted for that date."
I'm guessing that the programming error has to do with Postgres' transactions, and that my approach just won't work. If the exception isn't triggered, my message of "Your request has been submitted..." shows up on the return page just fine. I've decided to manually check for uniqueness after form validation and before saving, and that seems to work fine for now. Things like 'unique_for_date' and 'unique_together' seem to work great in the admin interface, but in the wild, you have to handle the exceptions yourself and I'm not really sure about the best ways to do it. Dan J. On Apr 20, 9:00 pm, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote: > On 21-Apr-08, at 12:50 AM, radioflyer wrote: > > > > > > > Hello, > > I need some help with the code after the IntegrityError exception. > > > <snip> > > s = Student.objects.get(pk=student_id) > > > if request.method == 'POST': > > form = ChangeForm(request.POST) > > if form.is_valid(): > > try: > > form.save() > > request.user.message_set.create(message="Your request has been > > submitted...") > > return HttpResponseRedirect(reverse(student, args=(s.id,))) > > except IntegrityError: > > request.user.message_set.create(message="Can't do that!") > > return HttpResponseRedirect(reverse(student, args=(s.id,))) > > </snip> > > > This code throws: > > Exception Type: ProgrammingError at /new_change/45/ > > Exception Value: current transaction is aborted, commands ignored > > until end of transaction block > > > Commenting out the 'message create' line, the code runs. If I leave > > it, Django attempts to insert my message string into the database. > > why are you using message_set? Would this not be the set of all > messages belonging to the particular user? > > -- > > regards > kghttp://lawgon.livejournal.comhttp://nrcfosshelpline.in/code/ --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---