(tables) add model method

1 view
Skip to first unread message

Michael

unread,
Jun 12, 2009, 8:43:24 AM6/12/09
to Django Apps
Hi there,

Is just started to work with django-tables and I think it's a great
app! One question (maybe I missed it in the information). Is it
possible to call a model method through django-tables?

See example below. Is it possible to call the get_product_url in the
model below so I can use the url in one of the columns?

I have tried it with

{% for row in rows %}
{{ row.get_product_url }}
{% endfor %}

and put get_product_url in my tables.py file but that doesn't seem to
work.....

----models.py-----
from django.db import models

class Dixons(models.Model):
name = models.CharField(max_length=200)
price = models.IntegerField()
link = models.CharField(max_length=300)
description = models.TextField(blank=True)
category = models.CharField(max_length=100)

def __unicode__(self):
return self.productname

class Meta:
ordering = ['name']

def get_product_url(self):
return '/shop/product/%s/' % self.id

Michael Elsdörfer

unread,
Jun 14, 2009, 6:54:34 PM6/14/09
to Django Apps
Try:

{{ row.data.get_product_url }}

Michael

Michael

unread,
Jun 15, 2009, 4:08:58 AM6/15/09
to Django Apps
Yep. That works just fine.

Thanks for the support!

On Jun 15, 12:54 am, Michael Elsdörfer <elsdoer...@gmail.com> wrote:
> Try:
>
> {{ row.data.get_product_url }}
>
> Michael
Reply all
Reply to author
Forward
0 new messages