forms.py 801 B

12345678910111213141516171819202122232425262728
  1. from django.forms import ModelForm
  2. from django.utils import timezone
  3. from django_select2.forms import Select2Widget
  4. from djadhere.forms import ReadOnlyModelForm
  5. from .models import Service, ResourceAllocation
  6. class ServiceForm(ModelForm):
  7. class Meta:
  8. model = Service
  9. fields = ('adhesion', 'service_type', 'label', 'notes', 'active',)
  10. widgets = {
  11. 'adhesion': Select2Widget(),
  12. }
  13. class ResourceAllocationForm(ReadOnlyModelForm):
  14. def __init__(self, *args, **kwargs):
  15. initial = kwargs.get('initial', dict())
  16. initial.update({'start': timezone.now()})
  17. super().__init__(*args, **kwargs)
  18. class Meta:
  19. model = ResourceAllocation
  20. fields = ('service', 'resource', 'start',)
  21. readonly_fields = ('start',)