What version of Django are you on? Later versions have an assignment tag helper that makes this easier.