Hello, I have the following models:
class Categoria(models.Model):
nombre = models.CharField(max_length=50)
def __str__(self):
return self.nombre
class Proveedor(models.Model):
razon_social = models.CharField(max_length=100, unique=True)
...
categoria = models.ManyToManyField(Categoria)
def __unicode__(self):
return self.razon_social
In my views.py I am generating an excel report where I want to show the categories of each of the providers:
for proveedor in Proveedor.objects.all().filter(estado=1):
...
ws.cell(row=cont, column=8).value = proveedor.categoria.all.join(", ")
It generates the following error:
invalid syntax (views.py, line 381)
That is, the way I want to display the categories is wrong, maybe some suggestion.
Diego, the method
all
belongs toQuerySet
, therefore you cannot apply the functionjoin
that is used for text strings.If you want to apply it to category names, you could do something like this:
It's simple, what you're actually doing is something like this: