Reputation: 908
Here is my current setup:
What I am looking to do is two things:
I want to include a new template if the boolean field value is true, for example
{% if clearance=true %} {% include example.html %} {% endif %}
I think that is easy(ish) but I cant work out how to get the value into a view then out into my template
I want to be able to define a new view called clearance that lists under "/clearance" that lists all products with the clearance boolean filed. I have one base polymorphic model and sevral other models that extend from there, Accessory is just one I have given as an example
This I think maybe slightly harder due to polymorphic, but I could be wrong.
Upvotes: 2
Views: 1220
Reputation: 239290
You're pretty much there on including a template for clearance items, you're just not using the right syntax:
{% if object.clearance %}{% include 'example.html' %}{% endif %}
Where product
is the current product within the forloop or whatever.
For the clearance view all you need is:
class ProductClearanceView(ListView):
model = Product
template_name = 'products/clearance.html'
def get_queryset(self):
qs = super(ProductClearanceView, self).get_queryset()
return qs.filter(clearance=True)
Upvotes: 2