Re: ORM Query question

2015-07-13 Thread Joss Ingram
Ok, thanks.

On Monday, 13 July 2015 16:14:29 UTC+1, Avraham Serour wrote:
>
> Personally I don't see obvious errors, but it is hard to tell with only 
> this small snippet.
>
> If it works what are you worried about? Performance? If you are having 
> performance problems you can try caching the query
>
> On Mon, Jul 13, 2015 at 6:08 PM, Joss Ingram <joss@gmail.com 
> > wrote:
>
>> Ok, thanks fair enough.
>>
>> my Question then is :
>>
>> Is the query above bad?
>>
>> On Mon, Jul 13, 2015 at 4:00 PM, Avraham Serour <tov...@gmail.com 
>> > wrote:
>>
>>> You told a story but didn't ask a question
>>>
>>> On Mon, Jul 13, 2015 at 5:54 PM, Joss Ingram <joss@gmail.com 
>>> > wrote:
>>>
>>>> I'm not getting much joy with my question, is there too little info? 
>>>>
>>>> On Friday, 10 July 2015 15:31:50 UTC+1, Joss Ingram wrote:
>>>>>
>>>>> Hi, 
>>>>>
>>>>> In my models I have an event index page type, which can have child 
>>>>> event pages, each event page can be tagged (using taggit), and I want to 
>>>>> produce a list of distinct tags used in the events that belong to that 
>>>>> event index on the index itself. I'm using the Django CMS Wagtail, but I 
>>>>> guess this is really a Django ORM query question. I''ve got some code as 
>>>>> part of my model which is working but I don't think it's the most 
>>>>> efficient 
>>>>> way of doing this. Still trying unlearn doing things with SQL and learn 
>>>>> how 
>>>>> the same thing should be done in Django.
>>>>>
>>>>> My code as part of the event index class is 
>>>>>
>>>>> @property
>>>>> def event_tag_list(self):
>>>>> child_events = EventPage.objects.live().descendant_of(self)
>>>>> return 
>>>>> Tag.objects.filter(mysite_eventpagetag_items__isnull=False).filter(mysite_eventpagetag_items__content_object_id=child_events).order_by('slug').distinct('slug')
>>>>>
>>>>> Any feedback would be appreciated.
>>>>>
>>>>> Thanks
>>>>>
>>>>> Joss
>>>>>
>>>>> 
>>>>>
>>>>>  -- 
>>>> 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...@googlegroups.com .
>>>> To post to this group, send email to django...@googlegroups.com 
>>>> .
>>>> Visit this group at http://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/61cf7c97-ae40-4c71-a094-ff1d819a7ce5%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/61cf7c97-ae40-4c71-a094-ff1d819a7ce5%40googlegroups.com?utm_medium=email_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/django-users/qB8W-I3jJWg/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> django-users...@googlegroups.com .
>>> To post to this group, send email to django...@googlegroups.com 
>>> .
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAFWa6t%2B1dpT%3D3oYG%2BqRopr9vWWXwY573%2BM%2BzkuT8ijxwYXo%2Brg%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/CAFWa6t%2B1dpT%3D3oYG%2BqRopr9vWWXwY573%2BM%2BzkuT8ijxwYXo%2Brg%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>> 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...@googlegroups.com .
>> To pos

Re: ORM Query question

2015-07-13 Thread Avraham Serour
Personally I don't see obvious errors, but it is hard to tell with only
this small snippet.

If it works what are you worried about? Performance? If you are having
performance problems you can try caching the query

On Mon, Jul 13, 2015 at 6:08 PM, Joss Ingram <joss.ing...@gmail.com> wrote:

> Ok, thanks fair enough.
>
> my Question then is :
>
> Is the query above bad?
>
> On Mon, Jul 13, 2015 at 4:00 PM, Avraham Serour <tovm...@gmail.com> wrote:
>
>> You told a story but didn't ask a question
>>
>> On Mon, Jul 13, 2015 at 5:54 PM, Joss Ingram <joss.ing...@gmail.com>
>> wrote:
>>
>>> I'm not getting much joy with my question, is there too little info?
>>>
>>> On Friday, 10 July 2015 15:31:50 UTC+1, Joss Ingram wrote:
>>>>
>>>> Hi,
>>>>
>>>> In my models I have an event index page type, which can have child
>>>> event pages, each event page can be tagged (using taggit), and I want to
>>>> produce a list of distinct tags used in the events that belong to that
>>>> event index on the index itself. I'm using the Django CMS Wagtail, but I
>>>> guess this is really a Django ORM query question. I''ve got some code as
>>>> part of my model which is working but I don't think it's the most efficient
>>>> way of doing this. Still trying unlearn doing things with SQL and learn how
>>>> the same thing should be done in Django.
>>>>
>>>> My code as part of the event index class is
>>>>
>>>> @property
>>>> def event_tag_list(self):
>>>> child_events = EventPage.objects.live().descendant_of(self)
>>>> return
>>>> Tag.objects.filter(mysite_eventpagetag_items__isnull=False).filter(mysite_eventpagetag_items__content_object_id=child_events).order_by('slug').distinct('slug')
>>>>
>>>> Any feedback would be appreciated.
>>>>
>>>> Thanks
>>>>
>>>> Joss
>>>>
>>>>
>>>>
>>>>  --
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/61cf7c97-ae40-4c71-a094-ff1d819a7ce5%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/61cf7c97-ae40-4c71-a094-ff1d819a7ce5%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/qB8W-I3jJWg/unsubscribe.
>> To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAFWa6t%2B1dpT%3D3oYG%2BqRopr9vWWXwY573%2BM%2BzkuT8ijxwYXo%2Brg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAFWa6t%2B1dpT%3D3oYG%2BqRopr9vWWXwY573%2BM%2BzkuT8ijxwYXo%2Brg%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAA%3DX%3DqeGwJ1OwOQw0C4jAr7nzWJUsKGeryAQ%3DgoicuJbCWr5HQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAA%3DX%3DqeGwJ1OwOQw0C4jAr7nzWJUsKGeryAQ%3DgoicuJbCWr5HQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6tJKaa08QFDgsdRQdqaL-T4UT3XvLSFkh%2BAmSSP6VW774w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ORM Query question

2015-07-13 Thread Joss Ingram
Ok, thanks fair enough.

my Question then is :

Is the query above bad?

On Mon, Jul 13, 2015 at 4:00 PM, Avraham Serour <tovm...@gmail.com> wrote:

> You told a story but didn't ask a question
>
> On Mon, Jul 13, 2015 at 5:54 PM, Joss Ingram <joss.ing...@gmail.com>
> wrote:
>
>> I'm not getting much joy with my question, is there too little info?
>>
>> On Friday, 10 July 2015 15:31:50 UTC+1, Joss Ingram wrote:
>>>
>>> Hi,
>>>
>>> In my models I have an event index page type, which can have child event
>>> pages, each event page can be tagged (using taggit), and I want to produce
>>> a list of distinct tags used in the events that belong to that event index
>>> on the index itself. I'm using the Django CMS Wagtail, but I guess this is
>>> really a Django ORM query question. I''ve got some code as part of my model
>>> which is working but I don't think it's the most efficient way of doing
>>> this. Still trying unlearn doing things with SQL and learn how the same
>>> thing should be done in Django.
>>>
>>> My code as part of the event index class is
>>>
>>> @property
>>> def event_tag_list(self):
>>> child_events = EventPage.objects.live().descendant_of(self)
>>> return
>>> Tag.objects.filter(mysite_eventpagetag_items__isnull=False).filter(mysite_eventpagetag_items__content_object_id=child_events).order_by('slug').distinct('slug')
>>>
>>> Any feedback would be appreciated.
>>>
>>> Thanks
>>>
>>> Joss
>>>
>>>
>>>
>>>  --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/61cf7c97-ae40-4c71-a094-ff1d819a7ce5%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/61cf7c97-ae40-4c71-a094-ff1d819a7ce5%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/qB8W-I3jJWg/unsubscribe.
> To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFWa6t%2B1dpT%3D3oYG%2BqRopr9vWWXwY573%2BM%2BzkuT8ijxwYXo%2Brg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAFWa6t%2B1dpT%3D3oYG%2BqRopr9vWWXwY573%2BM%2BzkuT8ijxwYXo%2Brg%40mail.gmail.com?utm_medium=email_source=footer>
> .
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA%3DX%3DqeGwJ1OwOQw0C4jAr7nzWJUsKGeryAQ%3DgoicuJbCWr5HQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ORM Query question

2015-07-13 Thread Avraham Serour
You told a story but didn't ask a question

On Mon, Jul 13, 2015 at 5:54 PM, Joss Ingram <joss.ing...@gmail.com> wrote:

> I'm not getting much joy with my question, is there too little info?
>
> On Friday, 10 July 2015 15:31:50 UTC+1, Joss Ingram wrote:
>>
>> Hi,
>>
>> In my models I have an event index page type, which can have child event
>> pages, each event page can be tagged (using taggit), and I want to produce
>> a list of distinct tags used in the events that belong to that event index
>> on the index itself. I'm using the Django CMS Wagtail, but I guess this is
>> really a Django ORM query question. I''ve got some code as part of my model
>> which is working but I don't think it's the most efficient way of doing
>> this. Still trying unlearn doing things with SQL and learn how the same
>> thing should be done in Django.
>>
>> My code as part of the event index class is
>>
>> @property
>> def event_tag_list(self):
>> child_events = EventPage.objects.live().descendant_of(self)
>> return
>> Tag.objects.filter(mysite_eventpagetag_items__isnull=False).filter(mysite_eventpagetag_items__content_object_id=child_events).order_by('slug').distinct('slug')
>>
>> Any feedback would be appreciated.
>>
>> Thanks
>>
>> Joss
>>
>>
>>
>>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/61cf7c97-ae40-4c71-a094-ff1d819a7ce5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/61cf7c97-ae40-4c71-a094-ff1d819a7ce5%40googlegroups.com?utm_medium=email_source=footer>
> .
>
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6t%2B1dpT%3D3oYG%2BqRopr9vWWXwY573%2BM%2BzkuT8ijxwYXo%2Brg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ORM Query question

2015-07-13 Thread Joss Ingram
I'm not getting much joy with my question, is there too little info? 

On Friday, 10 July 2015 15:31:50 UTC+1, Joss Ingram wrote:
>
> Hi, 
>
> In my models I have an event index page type, which can have child event 
> pages, each event page can be tagged (using taggit), and I want to produce 
> a list of distinct tags used in the events that belong to that event index 
> on the index itself. I'm using the Django CMS Wagtail, but I guess this is 
> really a Django ORM query question. I''ve got some code as part of my model 
> which is working but I don't think it's the most efficient way of doing 
> this. Still trying unlearn doing things with SQL and learn how the same 
> thing should be done in Django.
>
> My code as part of the event index class is 
>
> @property
> def event_tag_list(self):
> child_events = EventPage.objects.live().descendant_of(self)
> return 
> Tag.objects.filter(mysite_eventpagetag_items__isnull=False).filter(mysite_eventpagetag_items__content_object_id=child_events).order_by('slug').distinct('slug')
>
> Any feedback would be appreciated.
>
> Thanks
>
> Joss
>
> 
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/61cf7c97-ae40-4c71-a094-ff1d819a7ce5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ORM Query question

2015-07-10 Thread Joss Ingram
Hi, 

In my models I have an event index page type, which can have child event 
pages, each event page can be tagged (using taggit), and I want to produce 
a list of distinct tags used in the events that belong to that event index 
on the index itself. I'm using the Django CMS Wagtail, but I guess this is 
really a Django ORM query question. I''ve got some code as part of my model 
which is working but I don't think it's the most efficient way of doing 
this. Still trying unlearn doing things with SQL and learn how the same 
thing should be done in Django.

My code as part of the event index class is 

@property
def event_tag_list(self):
child_events = EventPage.objects.live().descendant_of(self)
return 
Tag.objects.filter(mysite_eventpagetag_items__isnull=False).filter(mysite_eventpagetag_items__content_object_id=child_events).order_by('slug').distinct('slug')

Any feedback would be appreciated.

Thanks

Joss



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e819245a-7885-4d56-9f9b-4bfac665f011%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ORM Query question

2010-04-12 Thread Tim Shaffer
Or, using range:

MyModel.objects.filter( Q(a__range=(1,5)) | Q(b__range=(20,70)) )

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ORM Query question

2010-04-12 Thread Tim Shaffer
http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects

MyModel.objects.filter( ( Q(a__gt=1) & Q(a__lt=5) ) | ( Q(b__gt=20) &
Q(b__lt=70) ) )

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ORM Query question

2010-04-12 Thread rebus_
On 13 April 2010 01:09, zweb  wrote:
> how do i do this kind of condition in django orm filter:
>
> ( 1 < a < 5)  or ( 20 < b < 70)
>
> select * from table where (a between 1 and 5) or (b between 20 and 70)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

http://docs.djangoproject.com/en/dev/ref/models/querysets/#range

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



ORM Query question

2010-04-12 Thread zweb
how do i do this kind of condition in django orm filter:

( 1 < a < 5)  or ( 20 < b < 70)

select * from table where (a between 1 and 5) or (b between 20 and 70)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.