Django - query for to give rows where one column Not equals to another column in same model
django, django-models, django-queryset, python
Solution
What you are searching for is:
https://docs.djangoproject.com/en/dev/topics/db/queries/#filters-can-reference-fields-on-the-model
SOLUTION:
from django.db.models import F
from datetime import datetime
min_date = datetime(2013,12,31)
result = Table.objects.filter(in_time__gte=min_date).\
exclude(in_time__eq=F('actual_time'))
Problem
My model have 3 fields ``` class Table(models.Model): in_time = models.DateTimeField(null=True, blank=True) actual_time = models.DateTimeField(null=True, blank=True) ``` i want to fetch results in this way : ``` select * from Table where in_time > '2013-12-31 00:00:00' and in_time != actual_time ``` So can anyone help me in completing this ``` result = Table.objects.filter(in_time__gte = '2013-12-31 00:00:00') ```