Accessing Model Property from Admin Index Page

19 views
Skip to first unread message

Lee

unread,
Nov 21, 2011, 10:13:00 PM11/21/11
to Django users
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

Daniel Roseman

unread,
Nov 22, 2011, 6:17:28 AM11/22/11
to django...@googlegroups.com
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.

Lee

unread,
Nov 22, 2011, 5:32:04 PM11/22/11
to Django users
DR - thanks for your reply. I need to display the model method result
(property) on index.html. Our index.html is heavily customized, and is
currently just a switchboard into the database tables via links like
this:

{{ app_list.1.models.21.admin_url }}

I'm hoping for a similarly simple way to show the results of model
methods on the same page so that we can provide a dashboard of
statistics from the database.

I appreciate your help.

Lee

Message has been deleted

Daniel Roseman

unread,
Nov 22, 2011, 6:19:22 PM11/22/11
to django...@googlegroups.com
OK, once again you haven't made it very clear, but I'm going to presume that app_list is a list of dictionaries containing lists of model instances (blurgh, but never mind). So, in that case, what was wrong with my previous answer: that you refer to a property in exactly the same way as any other model attribute - eg {{ app_list.1.models.21.my_property }} ?

--
DR.
Reply all
Reply to author
Forward
0 new messages