On Jan 12, 2008 10:59 AM, Darthmahon <[EMAIL PROTECTED]> wrote: > > Hey, > > I want to check if the current item I am printing in one list is also > available in another list. Basically I have a list of books and I want > to check if the user already has a particular book in their profile so > that instead of it saying "Add Book", it says "Remove Book". > > At the moment I am trying something like this: > > ################ > # File: custom_filters.py > ################ > @register.filter > def IN(value,arg): return value in arg > ################ > > ################ > # File: /books/views.py > ################ > {% for book in books %} > {% if book.id|IN:user_profile.books.all %} > <p>Remove Book</p> > {% else %} > <p>Add Book</p> > {% endif %} > {% endfor %} > ################ >
This is really your template file, right, not views.py? > user_profile has a many-to-many field relationship so that it gets a > list of all the books the user has. > > Basically, I get an error that tells me: > > Invalid Filter: 'IN' > > Is there a better way of checking if the current item in the for loop > is present in another list? In my experience "Invalid" whatever from template processing usually means I forgot to load my custom template tags/filters. So did you include a {% load custom_filters %} in your template file? Karen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---