Re: Custom Filter: Filter output based on a Python list
That's what I have been trying to do for quite sometime now! I can't seem to get the code right.
On Wednesday, October 2, 2013 2:13:25 PM UTC+3, Leo wrote:
-- On Wednesday, October 2, 2013 2:13:25 PM UTC+3, Leo wrote:
I'd cycle in the template through a list of exam periods, printing a table for each cycle.You have to pass the list of exam periods in the context of your view.Try and let me know.
Regards,
LeoLeonardo GiordaniAuthor of The Digital Cat
My profile on About.me - My GitHub page - My Coderwall profile
2013/10/2 +Emmanuel <elus...@gmail.com>Am working on a Django project that retrieves a student's details from the database, filters them based on the 'period of examination' (this is implemented as a python list in a custom filter) and displays the output.--Here is my custom filter:@register.filterdef periodofexamination(periodofexam): periodofexam = ['DECEMBER 2011', 'MAY 2011', 'DECEMBER 2010']for period in periodofexam:return periodThe template for displaying the output:{% extends 'base.html' %}{% load results_extras %}{% block title %}My Results{% endblock %}{% block content %}<h3> My Tentative Examination Results</h3><div class="alert alert-info">The results displayed below are tentative and for information purposes only.</div><table class='table table-striped table-bordered'><thead><th>Course Code</th><th>Course Name</th><th>Course Work</th><th>Exam</th><th>Grade</th><th>GPA</th><th> Year</th><th>Exam Period</th></thead> {% for query in queryset %}<tr><td>{{ query.coursecode}}</td><td>{{query.coursename}}</td><td>{{ query.coursework}}</td><td>{{ query.exam}}</td><td>{{query. exam|grade}}</td><td>{{query. exam|gpa}}</td><td>{{query. academicyear}}</td><td>{{ query.examperiod}}</td></tr> {% endfor %}</table>{% endblock %}The output:See the attached file (screenshot.png)The challenge:I would like to be able have the student results for a given exam period to appear each in their own table, for instance, all the results for exam period 'December 2011' should be in one table, all the results for exam period 'December 2010' should be in a different table. Currently, all the results appear in one table.How do I implement this using a custom filter?Thanks.
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...@googlegroups.com .
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users .
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bed2d4a9- .2439-41bd-81a0-be2c4964ca6b% 40googlegroups.com
For more options, visit https://groups.google.com/groups/opt_out .
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8bb1abd1-7cc4-44a4-aba4-2087b88d554d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home