This works and looks a bit cleaner:
records = query1 | query2
If you don’t want duplicates, then you will need to append .distinct()
:
records = (query1 | query2).distinct()
More Related Contents:
- Django dynamic model fields
- Django set default form values
- What’s the difference between select_related and prefetch_related in Django ORM?
- Can “list_display” in a Django ModelAdmin display attributes of ForeignKey fields?
- Django – No such table: main.auth_user__old
- How to create an object for a Django model with a many to many field?
- django abstract models versus regular inheritance
- Django Unique Together (with foreign keys)
- Getting TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries
- Django : Table doesn’t exist
- Get all related Django model objects
- Django Rest Framework and JSONField
- How to filter objects for count annotation in Django?
- How do I separate my models out in django?
- Writing a __init__ function to be used in django model
- Easiest way to rename a model using Django/South?
- Customize/remove Django select box blank option
- Duplicating model instances and their related objects in Django / Algorithm for recusrively duplicating an object
- Good ways to sort a queryset? – Django
- Resize fields in Django Admin
- Django DoesNotExist
- Identify the changed fields in django post_save signal
- Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given
- python_2_unicode_compatible error
- Django foreign key relation in template
- Django get_profile() method not working on extended User model
- How to store a dictionary on a Django Model?
- How to properly use the “choices” field option in Django
- update django database to reflect changes in existing models
- Django admin – inline inlines (or, three model editing at once)