django orm code example

Example 1: django objects.create()

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

Example 2: and in django query filter

Blog.objects.filter(entry__headline__contains='Lennon', entry__pub_date__year=2008)

Example 3: django model query join

Blog.objects.filter(entry__headline__contains='Lennon').filter(entry__pub_date__year=2008)

Example 4: django delete object

SomeModel.objects.filter(id=id).delete()

Example 5: django or

from django.db.models import Q
User.objects.filter(Q(income__gte=5000) | Q(income__isnull=True))

Example 6: django orm

Django ORM provides an elegant and powerful way to interact with the database. ORM stands for Object Relational Mapper. It is just a fancy word describing how to access the data stored in the database in Object Oriented fashion.