1👍
Django templates are note meant for such complex queries.
There are a few ways you can handle this
One, create a custom django template tag
Two, create a class method which would provide this info.
Example
class Course:
...
def sutdent_assign_count(self):
#Your query goes here..
0👍
You have far too much logic in the template. Create a method on one of your model classes that actually returns the number you want; I’d propose one, but it’s too unclear what you’re doing (why the .all.0
, aren’t the other results important? Why course.course_set, is that a many to many to itself?). What are your models like?
How would you describe what you are displaying in English? That probably gives a hint to what kind of method you should create.
- Why date range return empty query?
- Django Form Validation Error?
- Display time stored in database in HTML (django)
- Clean() method causes files to lose data using POST form
Source:stackexchange.com