On Mon, Aug 31, 2009 at 9:37 AM, stevedegrace<degr...@gmail.com> wrote:
>
> Hi guys,
>
> I'm making a refback type linkback app for my hobby CMS. I want to
> find all the unique page targets. I am thinking broadly of a couple of
> ways to do it. One with the ORM sort of line this:
>
> targets = list(set([linkback.target_url for linkback in
> LinkBacks.objects.all()]))
>
> This seems like way too much work being done by the framework and the
> database for a table which could in theory get very large. The other
> way I was thinking of doing it was like this:
>
> from django.db import connection
> cursor = connection.cursor()
> cursor.execute("SELECT target_url FROM linkbacks_linkback DISTINCT")
> targets = [item[0] for item in cursor.fetchall()]
>
> I'm leaning towards number 2, but I wonder if there is a better way to
> do this with the Django ORM.

Sure:

LinkBacks.objects.values_list('target_url', flat=True).distinct()

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~----------~----~----~----~------~----~------~--~---

Reply via email to