from django.forms import ModelForm from django.utils import timezone from django_select2.forms import Select2Widget from djadhere.forms import ReadOnlyModelForm from .models import Service, ResourceAllocation class ServiceForm(ModelForm): class Meta: model = Service fields = ('adhesion', 'service_type', 'label', 'notes', 'active',) widgets = { 'adhesion': Select2Widget(), } class ResourceAllocationForm(ReadOnlyModelForm): def __init__(self, *args, **kwargs): initial = kwargs.get('initial', dict()) initial.update({'start': timezone.now()}) super().__init__(*args, **kwargs) class Meta: model = ResourceAllocation fields = ('service', 'resource', 'start',) readonly_fields = ('start',)