Re: test if model object fits into QuerySet without executing SQL?

2019-03-18 Thread jgibson
result = qs1.difference(qs2)

if Result is length 0 then all of 1 is in 2.

On Monday, March 18, 2019 at 8:15:19 AM UTC-4, Thomas Klopf wrote:
>
> Hello,
>   Yes exactly that, if mo1 is in qs2. BUT without running the SQL on the 
> database, if possible.
>
> Thanks!
> Tom
>
>
> On Friday, March 15, 2019 at 1:34:34 PM UTC+1, jgi...@caktusgroup.com 
> wrote:
>>
>> Tom,
>>
>> Could you clarify "fits into"?
>>
>> qs1 = Table.objects.all()
>> qs2 = Table.objects.filter(color='blue')
>>
>>
>> mo1 = qs1[0]
>>
>>
>> Are you trying to determine if mo1 is in qs2?
>>
>> Best
>>
>> On Friday, March 15, 2019 at 7:46:14 AM UTC-4, Thomas Klopf wrote:
>>>
>>> Hi all,
>>>   Please I have a question, couldn't find any answer for it..
>>>
>>>   Let's say I have 2 QuerySets:
>>>   1) Select all records from table
>>>   2) Select all records from table where color = "blue"
>>>
>>> So QuerySet #2 is more restricted than QuerySet #1
>>>
>>> So question is - if I get a model object from QuerySet #1, is it 
>>> possible to check if the model object is 'filtered'  or fits into QuerySet 
>>> #2, without actually executing the SQL for QuerySet #2 to find the record 
>>> again?
>>>
>>> I'm asking because running the SQL for QuerySet #2 is expensive, ideally 
>>> would test if the record fits into the QuerySet in purely python/django.
>>>
>>> Thanks in advance!
>>> Tom
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c5314fff-37cf-4763-9ab8-2c055add3901%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: test if model object fits into QuerySet without executing SQL?

2019-03-18 Thread Jani Tiainen
Hi,

Note that Django querysets are lazy.

So running:

qs1 = MyModel.objects.all()

As is, doing that doesn't execute any queries. If you want filtered
objects, just add filter:

qs2 = qs1.filter(color="blue")

qs2 is not even evaluated yet. You need actually cause something that
evaluates queryset.

But if you want to fetch all objects from qs1 and then apply some
"filtering" you can just evaluate whole queryset and it's results
will be cached. You can use list comprehensions or itertools to filter your
objects in Python.


On Mon, Mar 18, 2019 at 2:16 PM Thomas Klopf  wrote:

> Hello,
>   Yes exactly that, if mo1 is in qs2. BUT without running the SQL on the
> database, if possible.
>
> Thanks!
> Tom
>
>
> On Friday, March 15, 2019 at 1:34:34 PM UTC+1, jgi...@caktusgroup.com
> wrote:
>>
>> Tom,
>>
>> Could you clarify "fits into"?
>>
>> qs1 = Table.objects.all()
>> qs2 = Table.objects.filter(color='blue')
>>
>>
>> mo1 = qs1[0]
>>
>>
>> Are you trying to determine if mo1 is in qs2?
>>
>> Best
>>
>> On Friday, March 15, 2019 at 7:46:14 AM UTC-4, Thomas Klopf wrote:
>>>
>>> Hi all,
>>>   Please I have a question, couldn't find any answer for it..
>>>
>>>   Let's say I have 2 QuerySets:
>>>   1) Select all records from table
>>>   2) Select all records from table where color = "blue"
>>>
>>> So QuerySet #2 is more restricted than QuerySet #1
>>>
>>> So question is - if I get a model object from QuerySet #1, is it
>>> possible to check if the model object is 'filtered'  or fits into QuerySet
>>> #2, without actually executing the SQL for QuerySet #2 to find the record
>>> again?
>>>
>>> I'm asking because running the SQL for QuerySet #2 is expensive, ideally
>>> would test if the record fits into the QuerySet in purely python/django.
>>>
>>> Thanks in advance!
>>> Tom
>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a09cf16e-8f9c-4bf0-b382-708ba21d28bd%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Jani Tiainen
Software wizard

https://blog.jani.tiainen.cc/

Always open for short term jobs or contracts to work with Django.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91oeVhEmC2kGeGmHYjRcq1KJJvhxwbUBEyHv8zdriHDF1eQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: test if model object fits into QuerySet without executing SQL?

2019-03-18 Thread Thomas Klopf
Hello,
  Yes exactly that, if mo1 is in qs2. BUT without running the SQL on the 
database, if possible.

Thanks!
Tom


On Friday, March 15, 2019 at 1:34:34 PM UTC+1, jgi...@caktusgroup.com wrote:
>
> Tom,
>
> Could you clarify "fits into"?
>
> qs1 = Table.objects.all()
> qs2 = Table.objects.filter(color='blue')
>
>
> mo1 = qs1[0]
>
>
> Are you trying to determine if mo1 is in qs2?
>
> Best
>
> On Friday, March 15, 2019 at 7:46:14 AM UTC-4, Thomas Klopf wrote:
>>
>> Hi all,
>>   Please I have a question, couldn't find any answer for it..
>>
>>   Let's say I have 2 QuerySets:
>>   1) Select all records from table
>>   2) Select all records from table where color = "blue"
>>
>> So QuerySet #2 is more restricted than QuerySet #1
>>
>> So question is - if I get a model object from QuerySet #1, is it possible 
>> to check if the model object is 'filtered'  or fits into QuerySet #2, 
>> without actually executing the SQL for QuerySet #2 to find the record again?
>>
>> I'm asking because running the SQL for QuerySet #2 is expensive, ideally 
>> would test if the record fits into the QuerySet in purely python/django.
>>
>> Thanks in advance!
>> Tom
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a09cf16e-8f9c-4bf0-b382-708ba21d28bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: test if model object fits into QuerySet without executing SQL?

2019-03-15 Thread Phako Perez
You can create query as

def get_query(value=None):
if value:
  query = “select all records from table where color = ‘" + value + “‘
  query = “select all records from table”

return query

Sent from my iPhone

> On Mar 15, 2019, at 6:20 AM, jgib...@caktusgroup.com wrote:
> 
> Tom,
> 
> Could you clarify "fits into"?
> 
> qs1 = Table.objects.all()
> qs2 = Table.objects.filter(color='blue')
> 
> 
> mo1 = qs1[0]
> 
> 
> Are you trying to determine if mo1 is in qs2?
> 
> Best
> 
>> On Friday, March 15, 2019 at 7:46:14 AM UTC-4, Thomas Klopf wrote:
>> Hi all,
>>   Please I have a question, couldn't find any answer for it..
>> 
>>   Let's say I have 2 QuerySets:
>>   1) Select all records from table
>>   2) Select all records from table where color = "blue"
>> 
>> So QuerySet #2 is more restricted than QuerySet #1
>> 
>> So question is - if I get a model object from QuerySet #1, is it possible to 
>> check if the model object is 'filtered'  or fits into QuerySet #2, without 
>> actually executing the SQL for QuerySet #2 to find the record again?
>> 
>> I'm asking because running the SQL for QuerySet #2 is expensive, ideally 
>> would test if the record fits into the QuerySet in purely python/django.
>> 
>> Thanks in advance!
>> Tom
>> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/26c692ef-6e97-4fa2-b5ef-6ebb24e408cb%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2A56D6F6-0AC6-4463-8887-F291E5915A9A%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: test if model object fits into QuerySet without executing SQL?

2019-03-15 Thread jgibson
Tom,

Could you clarify "fits into"?

qs1 = Table.objects.all()
qs2 = Table.objects.filter(color='blue')


mo1 = qs1[0]


Are you trying to determine if mo1 is in qs2?

Best

On Friday, March 15, 2019 at 7:46:14 AM UTC-4, Thomas Klopf wrote:
>
> Hi all,
>   Please I have a question, couldn't find any answer for it..
>
>   Let's say I have 2 QuerySets:
>   1) Select all records from table
>   2) Select all records from table where color = "blue"
>
> So QuerySet #2 is more restricted than QuerySet #1
>
> So question is - if I get a model object from QuerySet #1, is it possible 
> to check if the model object is 'filtered'  or fits into QuerySet #2, 
> without actually executing the SQL for QuerySet #2 to find the record again?
>
> I'm asking because running the SQL for QuerySet #2 is expensive, ideally 
> would test if the record fits into the QuerySet in purely python/django.
>
> Thanks in advance!
> Tom
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/26c692ef-6e97-4fa2-b5ef-6ebb24e408cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


test if model object fits into QuerySet without executing SQL?

2019-03-15 Thread Thomas Klopf
Hi all,
  Please I have a question, couldn't find any answer for it..

  Let's say I have 2 QuerySets:
  1) Select all records from table
  2) Select all records from table where color = "blue"

So QuerySet #2 is more restricted than QuerySet #1

So question is - if I get a model object from QuerySet #1, is it possible 
to check if the model object is 'filtered'  or fits into QuerySet #2, 
without actually executing the SQL for QuerySet #2 to find the record again?

I'm asking because running the SQL for QuerySet #2 is expensive, ideally 
would test if the record fits into the QuerySet in purely python/django.

Thanks in advance!
Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/64c7da25-67e2-498b-ba6c-4997122adf1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.