Blogger Template by Blogcrowds.

Introduction:
     This section will teach you to How to create not equal queryset filtering.

Method:
from django.db.models import Q
    Models.objects.exclude(MyField='foo')
    Models.objects.filter(~Q(MyField='foo'))

Introduction:
     This section will teach you to How to create complex query/filter using django Q objects.

Method:

from django.db.models import Q
    q_object = Q()
    q_object.add(Q(MyField__icontains='foo'), Q.OR) # OR'ing
    q_object.add(Q(MyField__icontains='foo'), Q.AND) # AND'ing
    q_object.add(Q(**{'MyField': 'foo'}), Q.AND) # QueryDict

Newer Posts Older Posts Home