Question

I'm trying to use django-tables2 in my project.

Here is my model

class Client(models.Model):
    comp = models.ForeignKey(Company)
    user = models.ForeignKey(User)
    def __unicode__(self):
        return u'%s\'s client data' % self.user
    class Meta:
        unique_together = (('user', 'comp'))

My table

class ClientTable(tables.Table):
    class Meta:
        model = Client
        fields = ('user')
        empty_text = _('No client')

My view

@login_required
def client_list(request):
    obj = {}
    try:
        clients = request.user.staff.company.client_set.all()
        client_table = ClientTable(clients) # <-- error from here
    except Staff.DoesNotExist:
        raise Http404
    obj['client_table'] = client_table
    obj['client_nb'] = clients.count()
    return render_to_response('company/client_list.html',
        obj, context_instance=RequestContext(request),)

This gives me this error:

cannot concatenate 'str' and 'tuple' objects
...
/usr/local/lib/python2.7/dist-packages/django_tables2/tables.py in init
self._sequence = Sequence(self._meta.fields + ('...',))

Was it helpful?

Solution

In your table definition, your field attribute must be a tuple.

fields = ('user')

This will be considered as a string, so you have to use

fields = ('user',)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top