Information on construction of object on form (philosophy)

64 views
Skip to first unread message

aRkadeFR

unread,
Nov 18, 2014, 12:21:38 PM11/18/14
to django-d...@googlegroups.com
Hello everyone,

Sorry to bother cause I did a ticket and got an answer by Tim Graham.
https://code.djangoproject.com/ticket/23760

But I wonder what's the philosophy of the Django developers community on
this ticket.
If Tim Graham want to be more explicit here, I would be really happy to
read from all of you.

From my point of view, in many case it's not a developer error, it can
be a template problem, a
generation of the data not updated before handled to the form __init__
problem, or so much
more.

Plus, it's not "new django developer" friendly.

If the object created, even though there's missing fields in the form,
can created the object
attribute with the default one, it would be much more friendly.

Thank you

Collin Anderson

unread,
Nov 18, 2014, 12:39:03 PM11/18/14
to django-d...@googlegroups.com, con...@arkade.info
Hello,

The way <input type="checkbox"> works in html forms, there's no distinction between "unchecked" and "form field not present". The browser won't even send an empty key for the the checkbox at all if it's not checked. Therefore, if the django form has a BooleanField and doesn't see a key in the data for it, then it needs to assume a false value.

The "data" argument on a django form is expected to be fairly raw browser data.

You may either want to create the fields on the form dynamically based on what keys are present in your data, or dynamically remove the non-existent fields from form.fields in __init__ once you have the data.

Collin

Collin Anderson

unread,
Nov 18, 2014, 12:52:24 PM11/18/14
to django-d...@googlegroups.com, con...@arkade.info
Philosopy-wise, I agree it would be good (and more secure) to error if the form detects that a field was not present in the html, however it's not possible to properly detect it in every case.

aRkadeFR

unread,
Nov 19, 2014, 2:46:31 AM11/19/14
to django-d...@googlegroups.com
Got it.
Thanks for the thorough explanation.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/95623339-37d2-4736-8939-725cfaa70f31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages