Trying to get django-tables to work with Django 1.1

3 views
Skip to first unread message

ssteiner

unread,
Sep 2, 2009, 7:16:25 AM9/2/09
to Django Apps
Exception Value:
'WSSWSite' object has no attribute 'get'
Exception Location: /Users/ssteiner/.virtualenvs/wssw1/lib/python2.6/
site-packages/django_tables/tables.py in _build_snapshot, line 261

It's pretty much straight out of the docs, WSSWSite is just a simple
model with a couple of simple out-of-the-box attributes.

class WSSWSite(models.Model):
name = models.CharField()
URL = models.URLField()

class WSSWSiteTable(tables.Table):
name = tables.Column(verbose_name="Site Name")
URL = tables.Column(verbose_name="Site URL")

My view is very simple, too:

def show_sites(request):
sites = WSSWSite.objects.all()
sites_table = WSSWSiteTable(sites)

return render_to_response("show_sites.html", {"sites":sites,
"sites_table":sites_table})

The guts of the template (the rest is simple setup stuff that works
fine w/o this middle).

{% for s in sites %}
{{s.name}} -- {{s.URL}}<br />
{% endfor %}

<table>
{% for column in sites_table.columns %}
{{column}}
{% endfor %}

{% for row in sites_table %}
<tr>
{% for value in row %}
<td>{{ value }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>

The error is:

Request Method: GET
Request URL: http://127.0.0.1:8000/show_sites/
Exception Type: AttributeError
Exception Value:
'WSSWSite' object has no attribute 'get'

I searched through the code but get() is not explicitly called
anywhere in django-tables anywhere and I'm pretty sure what I'm trying
to do follows the docs.

Any assistance would be greatly appreciated.

Thanks,

S

Michael Elsdörfer

unread,
Sep 2, 2009, 8:20:20 AM9/2/09
to Django Apps
You're subclassing "Table". Try "ModelTable."

I think I'm going to get rid of the non-Model implementation in the
future. There seems to be little use for it anyway.

ssteiner

unread,
Sep 2, 2009, 8:36:53 AM9/2/09
to Django Apps


On Sep 2, 8:20 am, Michael Elsdörfer <elsdoer...@gmail.com> wrote:
> You're subclassing "Table". Try "ModelTable."

Ah, it seemed the examples all used Table (and a list, not a query
result), so I didn't think to go looking for something different.

> > I think I'm going to get rid of the non-Model implementation in the
> future. There seems to be little use for it anyway.

I'm not sure how much it would get used. The obvious use-case is for
query results, for sure.

Thanks for your help!

S
Reply all
Reply to author
Forward
0 new messages