Hi, Kevin. Thanks for your reply.
I actually don't want to show the entered values - I basically want
the original form with values prior to the user submitting the form -
but with the validation errors that prompt them to enter new values in
the proper fields. I have already overridden the particular field's
clean method (clean_guests), but I don't understand how to preserve
the field's original value.
class RegistrationForm(ModelForm):
guests = forms.IntegerField(error_messages={'invalid': 'Please
enter a number greater than zero.'})
# enforce role/price limits
def clean_guests(self):
data = self.cleaned_data['guests']
if self.instance.price.parent.price_limit:
spaces_available = self.instance.price.spaces_available
delta = data - self.instance.guests
if delta > 0:
if spaces_available == 1 and delta > 1:
print self.instance.guests
raise forms.ValidationError("There is only 1 more
space available for this role.")
elif spaces_available > 1 and delta >
spaces_available:
raise forms.ValidationError("There are only %s
more spaces available for this role." % spaces_available)
else:
raise forms.ValidationError("Sorry, there are no
more spaces available for this role.")
return data
class Meta:
model = JosJeventsRegistration
fields = ['id', 'guests']
My view creates the form with the POST data in the standard fashion:
if request.method == 'POST':
fs = RegistrationFormSet(request.POST)
if fs.is_valid():
...
Which passes the form with the same post data and some error messages
back to the user.