Answer the question
In order to leave comments, you need to log in
How to add model elements to the end of the list?
There is a model:
class A(models.Models):
price = models.DecimalField(decimal_places=2, max_digits=12, default=0, verbose_name='Цена')
stock = models.PositiveIntegerField(blank=True, default=0)
a = A.objects.all()
b = a.filter(stock__gt=0).order_by('-price')
c = a.filter(stock=0).order_by('-price')
x = set()
x.update(b)
x.update(c)
return list(x)
Answer the question
In order to leave comments, you need to log in
from itertools import chain
b = a.filter(stock__gt=0).order_by('-price')
c = a.filter(stock=0)
x = chain(b, c)
All just read what set is here and the first links will give the right answer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question