ORM Query question

41 views
Skip to first unread message

Joss Ingram

unread,
Jul 10, 2015, 10:31:50 AM7/10/15
to django...@googlegroups.com
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

        

Joss Ingram

unread,
Jul 13, 2015, 10:54:06 AM7/13/15
to django...@googlegroups.com
I'm not getting much joy with my question, is there too little info? 

Avraham Serour

unread,
Jul 13, 2015, 11:02:59 AM7/13/15
to django-users
You told a story but didn't ask a question

--
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.

For more options, visit https://groups.google.com/d/optout.

Joss Ingram

unread,
Jul 13, 2015, 11:09:00 AM7/13/15
to django...@googlegroups.com
Ok, thanks fair enough.

my Question then is :

Is the query above bad?

--
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.

Avraham Serour

unread,
Jul 13, 2015, 11:14:29 AM7/13/15
to django-users
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

Joss Ingram

unread,
Jul 13, 2015, 11:16:59 AM7/13/15
to django...@googlegroups.com
Ok, thanks.
Reply all
Reply to author
Forward
0 new messages