You may be able to use this instead of re0inventing the wheel:
https://github.com/DirectEmployers/MyJobs/blob/master/myjobs/templatetags/common_tags.py