List Info

Thread: Help with Generic Views in Magic Removal Branch




Help with Generic Views in Magic Removal Branch
user name
2006-02-25 16:58:59
Hi

Please can someone help. I am following Tutorial4 for
generic views,
plus adapting it to the magic removal instructions on the
wiki page.
As far as I can tell i followed the instructions exactly,
But I get an
error stating that 'model' is not a valid paremeter to the
view.

I am sure its somthing dumb I have done, but if anyone spots
it I would
appreciate some help. I have pasted the ERROR and the
urls.py below
(cant see an attach  file option in GG).


Thanks in Advance,

S

********** ERROR ************

TypeError at /surveys/survey/1/
object_detail() got an unexpected keyword argument 'model'
Request Method: 	GET
Request URL: 	http://127.0.
0.1:8000/surveys/survey/1/
Exception Type: 	TypeError
Exception Value: 	object_detail() got an unexpected keyword
argument
'model'
Exception Location:
	H:\Programming\Python\Python24\lib\site-packages\djan
go\core\handlers\base.py
in get_response, line 72
Traceback (innermost last)

    *
H:\Programming\Python\Python24\lib\site-packages\djang
o\core\handlers\base.py
in get_response
        65. # Apply view middleware
        66. for middleware_method in self._view_middleware:
        67. response = middleware_method(request, callback,
callback_args, callback_kwargs)
        68. if response:
        69. return response
        70.
        71. try:
        72. response = callback(request, *callback_args,
**callback_kwargs) ...
        73. except Exception, e:
        74. # If the view raised an exception, run it
through exception
        75. # middleware, and if the exception middleware
returns a
        76. # response, use that. Otherwise, reraise the
exception.
        77. for middleware_method in
self._exception_middleware:
        78. response = middleware_method(request, e)
      ▶ Local vars

*******  URL ***************

from django.conf.urls.defaults import *

from bard.survey.models import Survey

info_dict = {'model': Survey}

urlpatterns = patterns('',
    (r'^$', 'bard.survey.views.index'),
   #(r'^survey/(?P<survey_id>\d+)/$',
'django.views.generic.list_detail.object_detail')
    (r'^survey/(?P<object_id>\d+)/$',
'django.views.generic.list_detail.object_detail',
info_dict)
)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Help with Generic Views in Magic Removal Branch
user name
2006-02-25 17:38:52
On Saturday 25 February 2006 16:58, ChaosKCW wrote:

> Please can someone help. I am following Tutorial4 for
generic views,
> plus adapting it to the magic removal instructions on
the wiki page.
> As far as I can tell i followed the instructions
exactly, But I get
> an error stating that 'model' is not a valid
paremeter to the view.

The tutorial is now badly out of date for magic-removal. 
Instead of 
taking a model and app_label, they take a 'queryset'
argument, which 
should be a QuerySet object.  QuerySet objects are what you
implicitly 
use in magic removal to do all lookups on the database.  For
instance, 
Poll.objects.all() is a QuerySet.  Because QuerySets are
'lazy', you 
can create them in your URL conf and the data won't be
retrieved at 
that point, but each time the generic view is actually
called.  In my 
urls.py I have something like this:

    (r'^sites/$', 'list_detail.object_list',
        {'queryset': Site.objects.all(),
         'template_name': 'cciw/sites/index'
        }
    ),
 
    (r'^sites/(?P<slug>.*)/$',
'list_detail.object_detail',
        {'queryset': Site.objects.all(),
         'slug_field': 'slug_name',
         'template_name': 'cciw/sites/detail'
         }
    ),
    ...

Note how I use all the 'Site' objects in the both cases,
but don't worry 
-- only in the first case does it actually result in all the
objects 
being retrieved from the db, in the second case the view
derives a new 
QuerySet, based on the one passed in, that only gets a
single object.

I personally think the new syntax is much nicer - no need
for 
'extra_lookup_args' etc.  If you wanted to have a
different ordering 
plus extra filtering, you could change Site.objects.all() to
e.g.
Site.objects.filter(visible=True).order_by('name').

One thing - I'm not sure all the generic views have been
updated yet.  I 
do know the above examples work.

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )