1

I am using django-datatable-view to show my data. I have a scenario that I need to retrieve records from a model, that satisfy certain conditions. For example, the request could be described as:

"SELECT * FROM model WHERE column_1='value_1' AND column_2='value_2'

How could I implement this? Actually, I saw the examples, but I don't have an efficient idea to do this. Would you please help me in View definition or refer to proper sample?

snoba
  • 153
  • 3
  • 8

2 Answers2

1

It seems that we should implement a get_queryset(self) method to apply on targeted filters:

def get_queryset(self):
    return Entity.objects.filter('item_1'='value_1')

While this could results in proper table values, but, the performance of loading decreases significantly. Maybe other solutions could save the performance, or we should use other techniques like caching.

snoba
  • 153
  • 3
  • 8
0

I think that the correct answer is pointed out in official documentation

You can filter QuerySet as it's shown in the example:

Entry.objects.filter(pub_date__year=2006)

For your case it could be:

Entry.objects.filter(column_1='value_1').filter(column_2='value_2')

Also it is possible duplicate of this topic

  • thanks for your comment. It is obvious that for any data retrieval from ORM, we could use filter. The django-datatable-view has it's own structure that we should keep in our considerations. – snoba Jan 20 '19 at 06:46