models.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from extras.forms import CustomFieldModelForm
  2. from extras.models import Tag
  3. from tenancy.models import Tenant, TenantGroup
  4. from utilities.forms import (
  5. BootstrapMixin, CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, SlugField,
  6. )
  7. __all__ = (
  8. 'TenantForm',
  9. 'TenantGroupForm',
  10. )
  11. class TenantGroupForm(BootstrapMixin, CustomFieldModelForm):
  12. parent = DynamicModelChoiceField(
  13. queryset=TenantGroup.objects.all(),
  14. required=False
  15. )
  16. slug = SlugField()
  17. class Meta:
  18. model = TenantGroup
  19. fields = [
  20. 'parent', 'name', 'slug', 'description',
  21. ]
  22. class TenantForm(BootstrapMixin, CustomFieldModelForm):
  23. slug = SlugField()
  24. group = DynamicModelChoiceField(
  25. queryset=TenantGroup.objects.all(),
  26. required=False
  27. )
  28. comments = CommentField()
  29. tags = DynamicModelMultipleChoiceField(
  30. queryset=Tag.objects.all(),
  31. required=False
  32. )
  33. class Meta:
  34. model = Tenant
  35. fields = (
  36. 'name', 'slug', 'group', 'description', 'comments', 'tags',
  37. )
  38. fieldsets = (
  39. ('Tenant', ('name', 'slug', 'group', 'description', 'tags')),
  40. )