After you play around with the admin site for a while, you'll probably notice a limitation-the edit forms require every field to be filled out, whereas in many cases you'd want certain fields to be optional. Let's say, for example, that we want our Author
model's email
field to be optional-that is, a blank string should be allowed. In the real world, you might not have an e-mail address on file for every author.
To specify that the email
field is optional, edit the Author
model (which, as you'll recall from Chapter 4, Models, lives in mysite/books/models.py
). Simply add blank=True
to the email
field, like so:
class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField(blank=True)
This tells Django that a blank value is indeed allowed for author's e-mail addresses. By default, all fields have blank=False
, which means blank values are not allowed.
There's something...