django-tables2 - Mix queryset and non-queryset data in table

49 views
Skip to first unread message

Max Demars

unread,
Apr 14, 2014, 9:33:34 AM4/14/14
to django...@googlegroups.com
Hi!

I would like to create a table via the Table.Meta.model with some columns that are non-queryset data. I manage to populate those columns manually in the view (see below), but it's impossible to sort the table with those columns: Cannot resolve keyword u'name' into field.

What is the proper way to mix queryset and non-queryset data in the same table?

models.py:

    class WMS(models.Model):
        alias = models.SlugField(max_length=50)
        date_created = models.DateTimeField(auto_now_add=True)
        date_updated = models.DateTimeField(auto_now=True)
        url = models.URLField()

forms.py:

    class WMSListTable(tables.Table):
        alias = tables.LinkColumn('editWMS', args=[A('pk')])
        name = tables.Column()
        type = tables.Column()
        version = tables.Column()
        valid = tables.BooleanColumn()
   
        class Meta:
            model = WMS
            fields = ('alias', 'url', 'date_created', 'date_updated')

views.py:

    from owslib.wms import WebMapService
   
    def listWMS(request):
        wms_list = WMS.objects.all()
        for wms in wms_list:
            try:
                instance = WebMapService(wms.url)
                wms.name = instance.identification.title
                wms.type = instance.identification.type
                wms.version = instance.identification.version
                wms.valid = True
            except:
                wms.valid = False
   
        wms_table = WMSListTable(wms_list)
        RequestConfig(request).configure(wms_table)
        return render(request,"basqui/manage_layer_wms_list.html", {'wms_list':wms_table},context_instance=RequestContext(request))


Thanks a lot!
-Max Demars


Reply all
Reply to author
Forward
0 new messages