forms.py 562 B

1234567891011121314151617181920
  1. from django import forms
  2. from django.contrib.admin.forms import AdminAuthenticationForm
  3. from django.contrib.admin.helpers import ActionForm
  4. class CustomAdminAuthenticationForm(AdminAuthenticationForm):
  5. class Media:
  6. css = {'all': ('path/to/media.css',)}
  7. def clean_username(self):
  8. username = self.cleaned_data.get('username')
  9. if username == 'customform':
  10. raise forms.ValidationError('custom form error')
  11. return username
  12. class MediaActionForm(ActionForm):
  13. class Media:
  14. js = ['path/to/media.js']