Sometimes in the
save() methods of a Django
form, you need to have additional form instance attributes available. A
sample case for this is having
user_id available. This is a simple
example of how to do it in Class-Based Views.
Assuming this form:
from django import forms ...
In my opinion, the concepts behind Django's model forms can be listed in just six (6) bullets. The bullets I've marked in bold at the top are the topic of this blog post, while the two of these that were covered in a previous blog post on Django ...
In my opinion, the concepts behind Django's non-model forms can be listed in just three (3) bullets:
Let's dig in!
If I construct a Django form:
# myapp/forms.py ...
One of the patterns we get positive feedback for mentioning in our book is overloading form fields.
The problem this pattern handles is the use case of when we have a model with a field(s) that allows for blank values, how do we force users to enter values?
Content Copyright © 2012-2018 Daniel Greenfeld. Proudly harnessed by Mountain, powered by Flask, and rendered by Frozen Flask, all of which take great advantage of Python.