Answer the question
In order to leave comments, you need to log in
Searching for a model by price, if the price can be specified in currency?
Hello.
There is a model:
class Flat(models.Model):
...
price = models.IntegerField('Цена в рублях/долларах/евро')
price_currency = models.CharField('Валюта')
pub_date = models.DateTimeField('Дата публикации')
...
Answer the question
In order to leave comments, you need to log in
from django.db.models import Q
queryset = Flat.objects.filter(
Q(price_currency='RUB', price__lte=price_max, price__gte=price_min) |
Q(price_currency='USD', price__lte=price_max*rate_usd, price__gte=price_min*rate_usd) |
Q(price_currency='EUR', price__lte=price_max*rate_eur, price__gte=price_min*rate_eur)
)
queryset = Flat.objects.filter(price__lte=200, price__gte=100).order_by('pub_date')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question