|
@@ -1,6 +1,6 @@
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
-from django.forms import ModelForm
|
|
|
|
|
|
+from django.forms import ModelForm, ValidationError
|
|
from django.db.models import Q
|
|
from django.db.models import Q
|
|
|
|
|
|
from coin.offers.models import OfferSubscription
|
|
from coin.offers.models import OfferSubscription
|
|
@@ -24,3 +24,14 @@ class ConfigurationForm(ModelForm):
|
|
Q(offer__configuration_type=self.instance.model_name) & (
|
|
Q(offer__configuration_type=self.instance.model_name) & (
|
|
Q(configuration=None) | Q(configuration=self.instance.pk)))
|
|
Q(configuration=None) | Q(configuration=self.instance.pk)))
|
|
self.fields['offersubscription'].queryset = queryset
|
|
self.fields['offersubscription'].queryset = queryset
|
|
|
|
+
|
|
|
|
+ def clean_offersubscription(self):
|
|
|
|
+ """
|
|
|
|
+ This check if the selected administrative subscription is linked to an
|
|
|
|
+ offer which use the same configuration type than the edited configuration.
|
|
|
|
+ """
|
|
|
|
+ offersubscription = self.cleaned_data['offersubscription']
|
|
|
|
+ if offersubscription.offer.configuration_type != self.instance.model_name():
|
|
|
|
+ raise ValidationError('Administrative subscription must refer an offer having a "{}" configuration type.'.format(self.instance.model_name()))
|
|
|
|
+
|
|
|
|
+ return offersubscription
|