@@ -1,31 +1,29 | |||
|
1 | 1 | from django import forms |
|
2 | 2 | from apps.main.models import Device |
|
3 | 3 | from .models import DDSConfiguration |
|
4 | 4 | |
|
5 | 5 | # from django.core.validators import MinValueValidator, MaxValueValidator |
|
6 | 6 | |
|
7 | 7 | class DDSConfigurationForm(forms.ModelForm): |
|
8 | 8 | |
|
9 | 9 | def __init__(self, *args, **kwargs): |
|
10 | 10 | #request = kwargs.pop('request') |
|
11 | 11 | super(DDSConfigurationForm, self).__init__(*args, **kwargs) |
|
12 | 12 | |
|
13 | 13 | instance = getattr(self, 'instance', None) |
|
14 | 14 | |
|
15 | 15 | if instance and instance.pk: |
|
16 | 16 | |
|
17 | 17 | devices = Device.objects.filter(device_type__name='dds') |
|
18 | 18 | |
|
19 | 19 | self.fields['experiment'].widget.attrs['readonly'] = True |
|
20 | self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] | |
|
20 | ||
|
21 | if instance.experiment is not None: | |
|
22 | self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] | |
|
21 | 23 | |
|
22 | 24 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] |
|
23 | 25 | |
|
24 | # | |
|
25 | # def clean(self): | |
|
26 | # # Custom validation to force an integer when type of unit = "Unit" | |
|
27 | # return | |
|
28 | 26 | |
|
29 | 27 | class Meta: |
|
30 | 28 | model = DDSConfiguration |
|
31 | 29 | exclude = ('type', 'parameters', 'status') No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now