Hi
I do not think you can include python in django templates so the various
uses of "unusedpremises" are ignored
You can generate a list of unused premises for the view by over-riding
the get_context_data method, perhaps something like this
### view.py
class PremisesListView(....)
class = Premises
etc...
def get_context_data(self, **kwargs):
context = super(PremisesListView,self).get_context_data(**kwargs)
context['unusedpremises'] =
Premises.objects.filter(in_use=False).order_by('name')
return context
The final loop in the template should then work
As ever, more info at
https://docs.djangoproject.com/en/1.5/topics/class-based-views/generic-display/
in the section "Adding extra context"
On Tue, 28 May 2013 05:02:30 -0700 (PDT)
tony gair <tonythegair@gmail.com> wrote:
>
>
> This file is used to print out the name of the premises with an update
> link , however I wanted to add a list of premises with the in_use flag
> set to false.
> Can anyone tell me what I am doing wrong?
>
>
> {% extends "base.html" %}
>
> {% block content %}
> <h2>Premises</h2>
> <ul>
> {% unusedpremises = [] %}
> {% for premises in object_list %}
> {% if premises.in_use %}
> <li>{{ premises.name }} <a href ="premuv/{{premises.id}}/"> Update </a>
>   </li>
> {% else unusedpremises.add(premises) %}
> {% endif %}
> {% endfor %}
> </ul>
> <h3>Unused Premises</h3>
> <ul>
> {% for premises in unusedpremises %}
> <li>{{ premises.name }} <a href ="premuv/{{premises.id}}/"> Update </a>
> %nbsp </li>
> {% endif %}
> {% endfor %}
> </ul>
> {% endblock %}
>
--
Drew Ferguson
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment