How to use filter in django
class Status (models.Model): someid = models.IntegerField () value = models.IntegerField () status_msg = models.CharField (max_length = 2000)
so my database look like:
20 1234567890 'some mdg'
20 4597434534 'some msg2'
20 3453945934 'sdfgsdf'
10 4503485344 'ddfgg'
so I need to get values ββcontaining someid indication between some values. so let's say
val1 = '1234567890'
val2 = '4414544544'
so my final result should be a list containing 2 entries for id = 20 how to implement this.
I tried to use
list = Status.objects.filter(someid = 20, value < val2, value > val1)
what's wrong? How to fix it.
thanks.
a source to share
The Django Query API does not use traditional comparison operators. It uses (field) __ (operatorname) = (value) style syntax.
Your request:
list = Status.objects.filter(someid=20, value__lt=val2, value__gt=val1)
See Django Docs on Making Queries
a source to share
You can also use range search * __ :
list = Status.objects.filter(someid=20, value__range=(val1+1, val2-1))
Remember that range searches are "on", so you need to adapt the range boundaries. If applicable, as stated above, it should result in the same listing that Imran posted. Range search also works with dates.
a source to share