About Model Form Fields
It's not recommendable to use the exclude
attribute for model form meta, because with big projects, you will likely forget to add new model fields that need to be excluded. Instead, you should have the boring list of fields
.
DON'T:
1 2 3 4 |
|
DO:
1 2 3 4 |
|
Here is a utility function that lists all the names of editable fields, but excludes the excluded ones:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Use this function in Django Shell and then replace the exclude
attribute with the fields
attribute in your code.
1 2 3 |
|
Tips and Tricks Programming Django 5.x Django 4.2 Django 3.2 Python 3 django-crispy-forms
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.