I was looking for some convenient method like this to use with the
object_list generic view.  But writing my own wrapper view only took 2
secs.

    def speaker_list(request, session_month):
        if not session_month in settings.SESSIONS:
            return HttpResponseNotFound()

        speakers = models.SpeakerInfo.objects.filter
(session__contains=session_month)

        speaker_info = {'queryset':speakers,
                    'template_name': 'speaker_list.html',
                    'template_object_name':'speaker',
                    'extra_context':{'session_month': session_month,},
                    }

        return object_list(request, **speaker_info)

The good thing about this is you can also validate the path variable
first.  Also don't forget to pass the path variable into the template
through the extra_context dictionary if you need it.


On Jan 4, 10:41 am, Bill Freeman <ke1g...@gmail.com> wrote:
> There may be an easier way, but I'd write aview, even if
> I then called thegenericviewfrom there.
>
> As you've probably figured out, your definition of thequeryset
> occurs once at import, when object_id isn't even defined, let
> alone coming from each request in turn.
>
> Bill
>
> On Sun, Jan 3, 2010 at 4:15 PM, Delacroy Systems
>
> <webad...@delacroy.co.za> wrote:
> > I want to display all the services for a particular business using the
> >genericview"object_detail". What I would like to do is pass the
> > value of an id from the url to thequeryset(into object_id) in
> > urls.py - or a better way to do this using the "object_detail"generic
> >view.
>
> > models.py:
> > class BusinessService(models.Model):
> >  business = models.ForeignKey(Business)
> >  service = models.ForeignKey(Service)
>
> > urls.py:
> > businessservice_list = {
> >    'queryset' : BusinessService.objects.filter(
> >                     business=object_id),
> > }
> > ...skip some detail...
> > (r'^showservice/(?P<object_id>\d+)/$', list_detail.object_detail,
> > businessservice_list),
>
> > businessservice_detail.html:
> > {% extends "portal/base.html" %}
> > {% block pagename %}Business Services{% endblock pagename %}
> > {% block content %}
> >    <h2>Business Services</h2>
> >                <h3>{{ businessservice.business }}</h3>
> >                <ul>
> >                        {% for business in object_list %}
> >                <li>{{ businessservice.service }}</li>
> >                        {% endfor %}
> >                </ul>
> > {% endblock content%}
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to