Skip to content
Advertisement

Django ORM How to query and get values when multiple conditions are fulfilled

I have following model

JavaScript

and Product model is as

JavaScript

I have the following sheet to calculate the min_days and max_days and insurance min max days.

Insurance_period Travel days Value
1-92 days 1-30 days 30
1-183 days 1-90 days 45
1-365 days 1-90 days 50
1-365 days 1-180 days 60

My problem is suppose I have 29 days as travel days and 90 days as Insurance days How do I calculate the value by using django query? As the actual value for 90 days of insurance days and 29 days travel time is 30.

I tried doing this way

JavaScript

I am getting 4 different result as my query satisfies all condition of above table any way I can do to satisfy above table conditon? to get 30 as value?

Advertisement

Answer

I think I got the answer I was missing order by

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement