Hi,
I am not sure if my method for displaying a table of model data isthe best
way to do it, but i essentially followed the examples in the docs and on
this forum... unfortunately my page processor does not seem to be working.
Here is the code:
In models.py:
class GeolSitesList(Page):
'''
A page to list GeolSites
'''
class Meta:
verbose_name = _("Sites List")
verbose_name_plural = _("Sites Lists")
In tables.py:
from ausgeolapp.models import *
import django_tables2 as tables
from django.utils.safestring import mark_safe
from django.utils.html import escape
class geolSitesTable(tables.Table):
class Meta:
model = geolsites
exclude = ("geom", )
attrs = {'class': 'SitesTable'}
def render_site(self, value):
return mark_safe(escape(value)+'<br><img id="sitethumb" width="300"
src="http://ausgeol.utas.edu.au/data/public/AusGeolSites/'+escape(value)+'/'
+escape(value)+'_thumb.jpg">')
In page_processors.py:
from mezzanine.pages.page_processors import processor_for
from django.db import models
from models import GeolSitesList
from django.http import HttpResponse
from django.template import loader
from ausgeolapp.models import *
from ausgeolapp.tables import geolSitesTable
import django_tables2 as tables
@processor_for(GeolSitesList)
def geolSites_List(request, page):
sitelist = geolsites.objects.all()
sitelisttable = geolSitesTable(sitelist)
sitelisttable.paginate(page=request.GET.get('page', 1), per_page=25)
return {"sitelisttable": sitelisttable}
I also tried: @processor_for("sites")
In geolsiteslist.html
{% extends "pages/page.html" %}
{% load mezzanine_tags staticfiles %}
{% block extra_assets %}
<link rel="stylesheet" href="{% static 'css\ausgeol-tables.css' %}" type=
"text/css" />
{% endblock %}
{% load django_tables2 %}
{% block main %}
{% render_table sitelisttable %}
{% endblock %}
I get the "Expected table or queryset, not 'str'." error because the
sitelisttable
is empty... the context is not being added because the page processor is
not being called. After hunting for suggestions I added the following to
urls.py:
from mezzanine.pages import page_processors
page_processors.autodiscover()
and also tried adding this to my url patterns but it made no difference and
I would have thought it was not needed since I am adding a
GeolSitesList page via mezzanine admin (the page is called 'sites'):
url("^sites/$", "mezzanine.pages.views.page", {"slug": "sites"}, name=
"GeolSitesList"),
and I tried this as well
url("^sites/$", "mezzanine.pages.views.page", {"slug": "sites"}, name=
"sites"),
I am not sure what else to try... please can someone point me to my
mistake. I am using Python 3.3, Postgresql 9.4 (PostGIS 2), Django 1.8.6,
Mezzanine 4.0.1, and the latest django-tables2.
Thanks,
Steve
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.