I have these models:
class Category(models.Model):
name = models.CharField(max_length=10)
uuid = models.CharField(max_length=36)
class Item(models.Model):
name = models.CharField(max_length=255)
uuid = models.CharField(max_length=36)
categories = models.ManyToManyField(Category, null=True)
brand = models.ForeignKey(Brand)
I'm trying to display Item
model in table with django-tables2, like this:
class ItemTable(tables.Table):
class Meta:
model = Item
attrs = {"class": "paleblue"}
fields = ("uuid", "name", "brand", "categories")
categories = tables.Column(empty_values=())
def render_categories(self, value):
return ', '.join([category.name for category in value.all()])
It works fine, except the Table
ignores the categories
field and
value
parameter is equals None
, and I'm getting error 'NoneType' object has no attribute 'all'
What am I doing wrong? Thanks.
Looks like this is bug in django-tables2 when using with django 1.7: https://github.com/bradleyayers/django-tables2/issues/211