forms.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from django import forms
  2. from dal import autocomplete
  3. from .models import Country, Genre, Film, Person
  4. class CountryForm(forms.ModelForm):
  5. class Meta:
  6. model = Country
  7. fields = ['name']
  8. class GenreForm(forms.ModelForm):
  9. class Meta:
  10. model = Genre
  11. fields = ['name']
  12. class FilmForm(forms.ModelForm):
  13. class Meta:
  14. model = Film
  15. fields = ['name', 'origin_name', 'slogan', 'length', 'year',
  16. 'trailer_url', 'cover', 'description', 'country', 'genres',
  17. "director", 'people']
  18. widgets = {
  19. 'people': autocomplete.ModelSelect2Multiple(
  20. url='films:person_autocomplete'),
  21. 'director': autocomplete.ModelSelect2(
  22. url='films:person_autocomplete'),
  23. 'country': autocomplete.ModelSelect2(
  24. url='films:country_autocomplete'),
  25. }
  26. class PersonForm(forms.ModelForm):
  27. class Meta:
  28. model = Person
  29. fields = ['name', 'origin_name', 'birthday', 'photo']
  30. widgets = {
  31. "birthday": forms.DateInput(attrs={'type': 'date'},
  32. format="%Y-%m-%d")
  33. }