Reputation: 65
{% for event in events.all %}
<tr>
<th>{{events.filter(date__exact = event.date)|length}}{% ifchanged event.date %}{{event.date}}{% endifchanged %}</th>
I am trying to fill out the same events with the same date. Then I can use it as rowspan for my table which would make it looks nice. But django doesn't allow doing filter in the view. How should I do it?
Upvotes: 1
Views: 765
Reputation: 101
Django does allow to filter in views. Once you import your model into views, then you can filter based on the fields in the model. See below for a sample:
models.py
from django.db import models
class My_Model(models.Model):
event_date = models.CharField()
views.py
from app.models import My_Model
def view_function():
query = My_Model.objects.filter(event_date='enter what you are looking for')
Upvotes: 2