Hello group,
Below is code for manual pre-save integrity check.
I think what I want is for the Validation Error (or an Integrity Error
if I go that way) to end up in forms.errors.

>From the form, I was doing:
  return HttpResponseRedirect(reverse(student, args=[s.id]))
when I had a validation error.

Can't quite get it to work from the model.

Thanks for any leg up...

from django.newforms.util import ValidationError # ????
from django.db import IntegrityError # ????

class Change(models.Model):

    other class code

def save(self):
  if self.id:
    record =
Change.objects.exclude(pk=self.id).filter(date=self.date).filter(student=self.student)
      if record:
        raise ValidationError, 'There is already a change for this
student on this date.'
      else:
        super(Change, self).save()
  else:
    record =
Change.objects.filter(date=self.date).filter(student=self.student)
      if record:
        raise ValidationError, 'There is already a change for this
student on this date.'
      else:
        super(Change, self).save()

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to