On Sun, Aug 30, 2009 at 9:37 PM, 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. > > Thanks for any thoughts on this, > > Stephen > > >
LinkBack.objects.values_list('target_url', flat=True).distinct() should do what you want. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Voltaire "The people's good is the highest law." -- Cicero "Code can always be simpler than you think, but never as simple as you want" -- Me --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---