How Add Multiple Fliters To A Model
I have inventory, status and transaction tables. Transaction has many to one inventory link and inventroy has one to one relation to status.
I am trying to pull all the transaction with check out > 3 sep and inventory which has staus checkout in Django.
I am using following syntax to pull in pyton, it give error
inventory = Inventory.objects.get(status = 2) transactions1 = Transaction.objects.filter((checkout_time__gt='2019-09-03') and inventory__in=inventory.id)
You can simply chain filters if you're looking for an
AND statemet like this:
If you want to be more explicit you can use Django's
from django.models import Q Transaction.objects.filter(Q(checkout_Time__gt='2019-09-03'), Q(inventory__status=2))
Using django's Q object you can build
OR queries with
| operator like this:
Transaction.objects.filter(Q(checkout_Time__gt='2019-09-03') | Q(inventory__status=2))
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module