In my admin for an object Chair
I have a TabularInline
for an arbitrary number of Desk
objects. I want every Chair
to always have at least one Desk
object associated with it. Is there a way to make the admin interface force the user to enter at least one Desk
? Like show an error if no Desk
is entered?
相关问题
- Django __str__ returned non-string (type NoneType)
- Django & Amazon SES SMTP. Cannot send email
- Django check user group permissions
- Django restrict pages to certain users
- UnicodeEncodeError with attach_file on EmailMessag
相关文章
- Profiling Django with PyCharm
- Why doesn't Django enforce my unique_together
- MultiValueDictKeyError in Django admin
- Django/Heroku: FATAL: too many connections for rol
- Django is sooo slow? errno 32 broken pipe? dcramer
- Django: Replacement for the default ManyToMany Wid
- Upgrading transaction.commit_manually() to Django
- UnicodeEncodeError when saving ImageField containi
Matthew Flanagan has a great example of how to require one valid form in a formset: http://code.google.com/p/wadofstuff/wiki/WadOfStuffDjangoForms and http://wadofstuff.blogspot.com/2009/08/requiring-at-least-one-inline-formset.html Hope that helps you out.
A generic FormSet
clean()
method for requiring at least one item:This should work for plain formsets, model formsets and in-line model formsets.
Using akaihola's answer, here is a more complete example:
Add this to your forms.py:
And then, in your admin.py: