Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Aug. 10, 2009 11:10:05

n.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

ModelForm validation


I have a form that inherits from ModelForm, and in my view,
form.is_valid returns true, then save() bombs out with validation
errors?!?

Does anyone know of a good tutorial/doc on this?

Thanks,
Sam
--~--~---------~--~----~------------~-------~--~----~
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
django-users+unsubscr...@googlegroups.com
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#2 Dec. 28, 2010 20:21:38

Axel B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

ModelForm validation


Hi all,

I have this little problem. In my little webapp I have a data model which
defines several required fields. Depending on WHO is logged on, some of
these fields should not be changed by the user and be pre-filled (or better:
post-filled) by the application.

Currently I delete the fields out of the formset like this:
# prevent entering missions for all other bases
del missionform.fields

so the field gets not rendered in the view. Which works nicely.

Unfortunately base is required, so the validation fails. Now how can I
insert the missing values into the POST data? I tried this:
if request.user.userflag.is_student:
logging.error("studen")
inst=FlownMission(
student=request.user,
base=request.user.studentinfo.current_base
)
flownmission = FlownMissionForm(request.POST, instance=inst)

which does not work at all :( . The validation fails all the time ... . I
just need to inject 2 required values somewhere in the POST data, but I have
no clue how.


Any help would be greatly appreciated, and I am a total django "newb" ... :)


Thanks & greetings,
Axel.

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 21st of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support