forms.py
26 lines
| 904 B
| text/x-python
|
PythonLexer
|
r12 | from django import forms | |
|
r13 | from apps.main.models import Device | |
|
r12 | from .models import DDSConfiguration | |
|
r26 | # from django.core.validators import MinValueValidator, MaxValueValidator | |
|
r12 | ||
class DDSConfigurationForm(forms.ModelForm): | |||
def __init__(self, *args, **kwargs): | |||
#request = kwargs.pop('request') | |||
super(DDSConfigurationForm, self).__init__(*args, **kwargs) | |||
|
r13 | ||
instance = getattr(self, 'instance', None) | |||
if instance and instance.pk: | |||
devices = Device.objects.filter(device_type__name='dds') | |||
|
r85 | if instance.experiment: | |
self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | |||
|
r26 | ||
self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |||
|
r13 | ||
|
r12 | ||
class Meta: | |||
model = DDSConfiguration | |||
|
r55 | exclude = ('type', 'parameters', 'status') |