I created a form class based on a model:

class MyModel(models.Model):
    increasing_field         = models.PositiveIntegerField()

class MyForm(forms.ModelForm):
    class Meta:
        model   = MyModel

I created a form to change an existing MyClass instance using POST
data to populate the form:

m = MyModel.objects.get(pk=n)
f = MyForm(request.POST, instance=m)

Every time f is being updated, f.increasing_field can only be greater
than the previous value.

How do I enforce that validation?

1 way I can think is to have clean_increasing_field take on an extra
argument that represents the previous value of  increasing_field:

def clean_increasing_field(self, previous_value)
    ...

This way I can just make sure the new value is greater than the
previous value. But it looks like clean_<fieldname>() methods cannot
take on extra arguments.

How can this validation be achieved?

--

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