I want to query the item from the database using django SmallIntegerField
. The code I used is
Here is the class defination:
class Equipment(models.Model):
asset_status = (
(0, 'online'),
(1, 'offline'),
(2, 'unknown'),
(3, 'wrong'),
(4, 'x'),
)
status = models.SmallIntegerField(
choices=asset_status, default=0, verbose_name='Device Status')
The query code I used is
def filter_queryset(self, qs):
sSearch = self.request.GET.get('search[value]', None)
print(sSearch)
if sSearch:
qs = qs.filter(Q(status__icontains=sSearch))
return qs
I want to query this column by 'online', 'offline' and so on. Do you know how to do this?
The reference I have searched are
Search choice field by the name in django - python
I also see the Choices
API in
https://django-model-utils.readthedocs.io/en/latest/utilities.html#choices
But there is no Q
. I am not sure whether it works. Could you please tell me about this?
And I searched for a method called get_FOO_display
, but I don't think it can be solved. Neither did I think it can be combined with Q
.
Thanks