From ed1f9c649a70a46a13d428b44282f87eab8dcbec Mon Sep 17 00:00:00 2001 From: bashmak Date: Fri, 14 Apr 2017 18:36:13 +0300 Subject: [PATCH] =?UTF-8?q?FIXBUG:=20=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B8=20=D0=B0=D0=B1=D0=BE=D0=BD=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B0=D1=8E?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20?= =?UTF-8?q?=D1=83=D0=BB=D0=B8=D1=86=D1=8B=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=BD=D0=B0=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BD=D0=B0=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abonapp/forms.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/abonapp/forms.py b/abonapp/forms.py index cb32d01..5129c43 100644 --- a/abonapp/forms.py +++ b/abonapp/forms.py @@ -27,6 +27,19 @@ def generate_random_password(): class AbonForm(forms.ModelForm): + def __init__(self, abon_group=None, *args, **kwargs): + super(AbonForm, self).__init__(*args, **kwargs) + if abon_group is not None: + abon_group_queryset = models.AbonStreet.objects.filter(group=abon_group) + elif self.instance is not None and self.instance.group is not None: + abon_group_queryset = models.AbonStreet.objects.filter(group=self.instance.group) + elif 'group' in self.initial.keys() and self.initial['group'] is not None: + abon_group_queryset = models.AbonStreet.objects.filter(group=self.initial['group']) + else: + abon_group_queryset = None + if abon_group_queryset is not None: + self.fields['street'].queryset = abon_group_queryset + username = forms.CharField(max_length=127, required=False, initial=generate_random_username, widget=forms.TextInput(attrs={ 'placeholder': _('login'), 'class': "form-control",