django query model code example

Example 1: q django

from django.db.models import Q

Q(question__startswith='Who') | Q(question__startswith='What')

Example 2: django objects.create()

SomeModel.objects.create(firstname='ricky', lastname='ticky')

Example 3: query set

A QuerySet is a list of a dictionary of objects in your database.

Example 4: objects.filter django

>>> Entry.objects.filter(blog_id=4)

Example 5: .save() in django

>>> one_entry = Entry.objects.get(pk=1)

Example 6: django 3.0 queryset examples

>>> Entry.objects.filter(
...     headline__startswith='What'
... ).exclude(
...     pub_date__gte=datetime.date.today()
... ).filter(
...     pub_date__gte=datetime.date(2005, 1, 30)
... )