Hi, I'm Daniel Greenfeld, and welcome to my blog. I write about Python, Django, and much more.

Adding Django form instance attributes

Monday, September 15, 2014 (permalink)

Sometimes in the clean(), clean_FOO or 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 ...
Read more ...

Core Concepts of Django ModelForms

Thursday, June 13, 2013 (permalink)

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 ...

Read more ...

Core Concepts of Django Forms

Friday, March 29, 2013 (permalink)

In my opinion, the concepts behind Django's non-model forms can be listed in just three (3) bullets:

  • Forms render HTML.
  • Forms are "just" Python constructs.
  • Forms validate dictionaries (Python's Key/Value structure).

Let's dig in!

Forms render HTML.

If I construct a Django form:

# myapp/forms.py ...
Read more ...

Overloading Django Form Fields

Wednesday, March 27, 2013 (permalink)

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?

For ...

Read more ...