Answer the question
In order to leave comments, you need to log in
Django filtering ForeignKey
Good afternoon!
models.py
class Delivery(models.Model):
created_on = models.DateTimeField(u"Дата создания", auto_now_add=True)
datedelivery = models.DateField(u"Дата отгрузки")
dateofperformance = models.DateTimeField(u"Дата исполнения")
partner = models.ForeignKey(Partner, verbose_name=u"Контрагент")
КОНТРАГЕНТЫ:
class Partner(models.Model):
name = models.CharField(max_length=100)
created_on = models.DateTimeField(auto_now_add=True)
forms.py
class DeliveryForm(forms.ModelForm):
partner = forms.ModelChoiceField(label='Контрагент', queryset=Delivery.objects.all())
Контрагента1
Контрагента1
Контрагента2
Контрагента1
Контрагента3
Контрагента4
Контрагента2
Контрагента5
forms.py
class DeliveryForm(forms.ModelForm):
partner = forms.ModelChoiceField(queryset=Delivery.objects.filter().values_list('partner', flat=True).order_by('partner').distinct())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question