Hi, On 8/19/07, Chris Hoeppner <[EMAIL PROTECTED]> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi there! > > I thought this is just the kind of questions you love :) > > I haven't been able to find concise information about this on the net. > > I need to construct a choices var for a field widget at runtime, with > the data from my database. Actually, I want to give a select field > options depending on the values in the database, and since there's no > separate table for those options, and it doesn't make sense creating one > just for this purpose, I resorted to list comprehensions to filter/map a > queryset into a valid choice list. > > It works like a charm, but I'm obviously getting duplicates, and the > choices are not sorted. > > My current code looks like this: > > all_props = Property.objects.all() > rooms_choices = [(p.rooms, p.rooms) for p in all_props] > > Ideally, I'd do something like "for p in all_props if p.rooms not in > rooms_choices" but I have no clue on how to access the being-built list, > nor how to compare to the values inside the tuple. > > Any ideas? :)
Yes, .order_by() and set(). I also found a function to remove duplicates from a list, but I'm sure you could also do this on the queryset. :) > ~Chris Kai --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---