Sorry for the late reply. I did as you suggested - overrided form's
clean method.For example when I did sth like this:
Template:
<form id="carForm" method="POST" action=".">
{{carForm.as_p}}
{{carPhotoForm.as_p}}
<input type="Submit" value="Add photo"/>
</form>
Model:
class Car(models.Model):
car_type = models.IntegerField()
class CarPhoto(models.Model):
photo = models.ImageField( upload_to = 'cars_photos/')
car = models.ForeignKey(Car)
View:
class CarForm(ModelForm):
class Meta:
model = Car
class CarPhotoForm(ModelForm):
class Meta:
model = CarPhoto
exclude = 'car'
def car(request):
carForm, carPhotoForm = CarForm(), CarPhotoForm()
if request.method == 'POST':
post = request.POST.copy()
carForm = CarForm(post)
carPhotoForm = CarPhotoForm(post)
return render_to_response('cars.html', { 'carForm':carForm,
'carPhotoForm':carPhotoForm})
then without calling form's is_valid method, the validation was
performed after submitting form.
Malcolm Tredinnick wrote:
> On Mon, 2009-03-23 at 17:46 +0100, Marek Wawrzyczek wrote:
>
>> I'd like to make a page, where the user will be able to edit a data of
>> his account and add photos. There will be 2 buttons: add photo, and
>> submit form. Add photo button will cause adding a photo to the server,
>> so the form will be submited, and then in the response generated by
>> django (so that the fields user entered before adding a photo weren't
>> cleaned) there will be error messages if the user filled the email
>> field for example "addres@". So I'd like to do validating of "non
>> image" fields only after submiting a form.
>>
>
> Nothing requires you to display the error messages on the HTML page. You
> can write your own form display method that only displays the errors if
> some other context variable is set, for example.
>
> However, you haven't mentioned what happens when you just try what you
> want to do. Does it work? If not, what goes wrong?
>
> Regards,
> Malcolm
>
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---