(tables) add model method

瀏覽次數:1 次
跳到第一則未讀訊息

Michael

未讀,
2009年6月12日 上午8:43:242009/6/12
收件者: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

未讀,
2009年6月14日 下午6:54:342009/6/14
收件者:Django Apps
Try:

{{ row.data.get_product_url }}

Michael

Michael

未讀,
2009年6月15日 凌晨4:08:582009/6/15
收件者: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
回覆所有人
回覆作者
轉寄
0 則新訊息