I need to pass a model to my template and then access its
attributes. Some of them start with an underscore, which turns out to
be a problem for the template mechanism.
I think there are two major roads to solve this:
- write new template tags
- add a new method to each of my models (lot of new code to write?)
Are there any other alternatives? Which is the best bet? Could you
kindly point me out a few urls where I can study those topics?
Thank you very much,
--
Fabio Natali
Rajesh Dhawan scrisse:
[...]
> > I need to pass a model to my template and then access its
> > attributes. Some of them start with an underscore, which turns out to
> > be a problem for the template mechanism.
> Alternatively, create a method/property (your second solution above)
> to access each one of them publically.
I added a couple of methods to my models, so to access to the
underscore methods/attributes but with different names. I get an error
though.
TemplateSyntaxError at /
Caught an exception while rendering: unbound method __unicode__() must be called with Fornitore instance as first argument (got nothing instead)
I put some excerpts in http://dpaste.com/75743/. Can anybody see
what's missing/wrong?
Thanks.
> -Rajesh D
All the best,
Fabio.
--
Fabio Natali
bruno desthuilliers wrote:
[...]
> Yeps : you're calling an instancemethod on a class. For what you're
> trying to do, you need classmethods, ie:
>
> @classmethod
> def verbosename(cls):
> return unicode(cls._meta.verbose_name)
It did the trick! Now everything's fine. And I advanced a small step
into the Python world.
See ya,
--
Fabio Natali