13👍
✅
You can’t enforce this on at the model level as @Greg details, but you can enforce it on a form by simply making the field required. This won’t prevent anyone with shell-level access from manually creating a UserProfile without a foo, but it will force anyone using a browser-based form method of creation.
8👍
Unfortunately, I don’t think this is possible at the model level because ManyToMany data is saved separately from other model fields. You should be able to enforce it at the admin level by specifying a custom form, and writing a clean() method on the form.
👤Greg
- How to get average from set of objects in Django?
- Determine if an attribute is a `DeferredAttribute` in django
- Django makemigrations not detecting project/apps/myapp
Source:stackexchange.com