10.4.4 Making Relations Optional in Forms

If you try to submit a Startup with no tags via our Startup create webpage, Django will error and insist that at least one Tag is mandatory. The same will happen for Post via the Post create webpage but for both Startup and Tag.

This is a somewhat baffling behavior. We know that many-to-many relationships are a separate table, and so the database is clearly not what requires this data. Django is enforcing this behavior. All of our forms are ModelForms, which means that Django is deriving this form behavior from our models.

Django model fields have a number of field options that change their behavior in a number of ways. As it turns out, one of these field options, blank, is built almost entirely for ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.