[CentralOH] Question > Django > Querys > comparing fields from same record.
Eric Floehr
eric at intellovations.com
Tue Sep 15 23:57:30 CEST 2015
Hi John,
For that, you'll want to use Django's F() objects. F stands for 'field' (or
column). So assuming your Django model for the MyTable table is also called
MyTable:
from django.db.models import F
from yourapp.models import MyTable
results = MyTable.objects.filter(foo=F('bar'))
More information can be found here:
https://docs.djangoproject.com/en/1.7/ref/models/queries/
Cheers,
Eric
On Tue, Sep 15, 2015 at 5:44 PM, John Cassidy <jocassid at gmail.com> wrote:
> I'm trying to perform a query like this:
>
> SELECT *
> FROM MyTable
> WHERE MyTable.foo = MyTable.bar
>
> Is there a way to create a where clause like this using the filter
> method? If not how could this be done?
>
> -John Cassidy
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20150915/46e2531b/attachment.html>
More information about the CentralOH
mailing list