On Tuesday, 22 November 2011 03:13:00 UTC, Lee wrote: > > I've opened a hundred docs/postings and can't find the correct syntax > for this simple task. > > In my model I have a method and a property to return the result of the > method: > > class MyModel(models.Model) > ... > def get_my_property(self): > return '1234' > my_property = property(get_my_property) > > Now I want to display this property on the index page in a {{ }} > variable tag. What is the correct syntax, and where can I find this in > the docs? > > Thanks very much for any help. > > Lee >
This question is not very clear. Exactly where do you want to display it? What template are you trying to edit? In template syntax, you access a property in exactly the way you access any other model attribute - by using dot syntax. For example, {{ my_instance.my_property }}. However, it is not clear where you would be getting the instance from in your template, since the "admin index" doesn't access any model instances. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/mDq-KBWY04IJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.