forms.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from django import forms
  2. from django.utils.translation import gettext as _
  3. from tenancy.models import *
  4. from utilities.forms import DynamicModelChoiceField, DynamicModelMultipleChoiceField
  5. __all__ = (
  6. 'ContactModelFilterForm',
  7. 'TenancyForm',
  8. 'TenancyFilterForm',
  9. )
  10. class TenancyForm(forms.Form):
  11. tenant_group = DynamicModelChoiceField(
  12. queryset=TenantGroup.objects.all(),
  13. required=False,
  14. null_option='None',
  15. initial_params={
  16. 'tenants': '$tenant'
  17. }
  18. )
  19. tenant = DynamicModelChoiceField(
  20. queryset=Tenant.objects.all(),
  21. required=False,
  22. query_params={
  23. 'group_id': '$tenant_group'
  24. }
  25. )
  26. class TenancyFilterForm(forms.Form):
  27. tenant_group_id = DynamicModelMultipleChoiceField(
  28. queryset=TenantGroup.objects.all(),
  29. required=False,
  30. null_option='None',
  31. label=_('Tenant group')
  32. )
  33. tenant_id = DynamicModelMultipleChoiceField(
  34. queryset=Tenant.objects.all(),
  35. required=False,
  36. null_option='None',
  37. query_params={
  38. 'group_id': '$tenant_group_id'
  39. },
  40. label=_('Tenant')
  41. )
  42. class ContactModelFilterForm(forms.Form):
  43. contact = DynamicModelMultipleChoiceField(
  44. queryset=Contact.objects.all(),
  45. required=False,
  46. label=_('Contact')
  47. )
  48. contact_role = DynamicModelMultipleChoiceField(
  49. queryset=ContactRole.objects.all(),
  50. required=False,
  51. label=_('Contact Role')
  52. )