On Tue, Mar 3, 2009 at 5:01 PM, dj <d.a.aberna...@gmail.com> wrote: > > I have a list of objects : ships= [<Ship: Oscar Dyson>, <Ship: Miller > Freeman> <Ship: Nancy Foster>,<Ship: Hi Ialakai>] > > Each ship object has these attributes with an associated value: > name Hi Ialakai > abbr WTEY > ship Hi Ialakai > cruise Dune > slug dune-wtey > > Given a variable containing the name of an attribute in the object > (EX: field=cruise) and the value they are searching for (EX: > value='Dune'), I want t get the objects with a matching attrtibute and > value. > (EX: Ship.objects.filter(field=value) > > How do I do this ? > > > > > > You can do it using the python kwarg syntax: Ship.objects.filter(**{field: value}). You want to make sure you sanitze field so that the user can't filter against something you don't want though.
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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---