Improved device validation

This commit is contained in:
Raphael Michel
2019-07-18 17:26:34 +02:00
parent 6d12b3780c
commit 85edbe4837

View File

@@ -173,6 +173,13 @@ class DeviceForm(forms.ModelForm):
super().__init__(*args, **kwargs)
self.fields['limit_events'].queryset = organizer.events.all()
def clean(self):
d = super().clean()
if not d['all_events'] and not d['limit_events']:
raise ValidationError(_('Your device will not have access to anything, please select some events.'))
return d
class Meta:
model = Device
fields = ['name', 'all_events', 'limit_events']