Django - How does a query query itself? -


i have 2 models

product   id:   delivery_date: datetimefield   contract: fk  contract   id:   safety_days: integerfield 

i need products deliver in next x days. x defined in contract safety_days.

products = product.objects.filter(    q(delivery_date__lte=(datetime.datetime.now() + timedelta(days=contract__safety_days))) ) 

however,i not able do:

days = contract__safety_days 

i not know how can reference object inside query dynamically.

best regards, ruben barros

you need use f expressions query. query following way:

products = product.objects.filter(     q(delivery_date__lte=(datetime.datetime.now() + timedelta(days=f('contract__safety_days')))) ) 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -