forms.py 1.7 KB

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