[CentralOH] Question > Django > Querys > comparing fields from same record.
eric at intellovations.com
Wed Sep 16 02:50:09 CEST 2015
Also, if you ever want to verify the query that is actually generated, you
results = MyTable.objects.filter(foo=F('bar'))
Which will output something like:
SELECT ... FROM "MyTable" WHERE "MyTable"."foo" = "MyTable"."bar"
Where ... is the list of columns in MyTable.
On Tue, Sep 15, 2015 at 5:57 PM, Eric Floehr <eric at intellovations.com>
> 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:
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the CentralOH