Order payments by date in refunds form

This commit is contained in:
Gabriel Augendre 2016-06-12 18:06:07 +02:00
parent 3ffde84ba4
commit 1e1846d501
No known key found for this signature in database
GPG key ID: D2B6A5B41FC438B1

View file

@ -15,7 +15,10 @@ class RefundForm(forms.ModelForm):
super(RefundForm, self).__init__(*args, **kwargs) super(RefundForm, self).__init__(*args, **kwargs)
if self.instance: if self.instance:
self.fields['payments'].initial = self.instance.payment_set.all() self.fields['payments'].initial = self.instance.payment_set.all()
self.fields['payments'].queryset = Payment.objects.filter(Q(refund=None) | Q(refund=self.instance)) self.fields['payments'].queryset = Payment\
.objects\
.filter(Q(refund=None) | Q(refund=self.instance))\
.order_by('-date')
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
# Save the refund # Save the refund