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
-- 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
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f351d25c-67f3-4f8e-b837-cf033c428ee0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment