Django error: 'QueryDict' object has no attribute '_meta'
I am very new to django so this is probably a noob question开发者_Python百科. I am trying to reuse django admin's change list view. I've created a admin model and want to provide the changelist template a list of these objects. In my view I have:
def placements(request):
partner_id = request.session.get('partner_id', 0)
self = PlacementAdmin(request.GET, Placement.objects.filter(partner=partner_id))
return render_to_response('publisher/placement/change_list.html', {'cl': self})
I get this error when I try to hit this function from a browser: 'QueryDict' object has no attribute '_meta' Could anyone tell me what the error is or provide an easier way to accomplish this in case I am on the wrong track completely.
Heres the complete trace:
Request Method: GET
Request URL: http://localhost:8080/publisher/
Django Version: 1.3 beta 1
Exception Type: AttributeError
Exception Value:
'QueryDict' object has no attribute '_meta'
Exception Location: /Users/imran/django_env/lib/python2.6/site-packages/django/contrib/admin/options.py in __init__, line 278
Python Executable: /Users/imran/django_env/bin/python
Python Version: 2.6.1
Python Path:
['.',
'.',
'/Users/imran/Workspaces/publisher/django/pub_admin',
'/Users/imran/django_env/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg',
'/Users/imran/django_env/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg',
'/Users/imran/django_env/lib/python26.zip',
'/Users/imran/django_env/lib/python2.6',
'/Users/imran/django_env/lib/python2.6/plat-darwin',
'/Users/imran/django_env/lib/python2.6/plat-mac',
'/Users/imran/django_env/lib/python2.6/plat-mac/lib-scriptpackages',
'/Users/imran/django_env/Extras/lib/python',
'/Users/imran/django_env/lib/python2.6/lib-tk',
'/Users/imran/django_env/lib/python2.6/lib-old',
'/Users/imran/django_env/lib/python2.6/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',
'/Users/imran/django_env/lib/python2.6/site-packages']
It's best to post the traceback error when posting a question!
That said, the error comes from you passing request.GET
to a ModelAdmin
admin object which isn't expecting it.
You have a long road of troubles ahead of you though, as you're trying to use the magical change_list view template which is operated on by a collection of even more magical, undocumented template tags, which just doesn't normally appear in the same sentence as new to django.
I think you're on the wrong track simply because django's admin is not easy to hack into.
At a minimum, you'd have to pass in your template a ChangeList
object for the cl
variable.
If you really want to do this, the only advice I can give is to take a look at django.contrib.admin.options.ModelAdmin.changelist_view()
since that's what you're trying to replicate.
Seriously though I'd like to talk you out of this. Django's actually really fun to work with!
精彩评论