Re: Passing a parameter into a queryset for a generic view
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 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 > > 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\d+)/$', list_detail.object_detail, > > businessservice_list), > > > businessservice_detail.html: > > {% extends "portal/base.html" %} > > {% block pagename %}Business Services{% endblock pagename %} > > {% block content %} > > Business Services > > {{ businessservice.business }} > > > > {% for business in object_list %} > > {{ businessservice.service }} > > {% endfor %} > > > > {% 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.
Re: Passing a parameter into a queryset for a generic view
There may be an easier way, but I'd write a view, even if I then called the generic view from there. As you've probably figured out, your definition of the queryset 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 wrote: > I want to display all the services for a particular business using the > generic view "object_detail". What I would like to do is pass the > value of an id from the url to the queryset (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\d+)/$', list_detail.object_detail, > businessservice_list), > > businessservice_detail.html: > {% extends "portal/base.html" %} > {% block pagename %}Business Services{% endblock pagename %} > {% block content %} > Business Services > {{ businessservice.business }} > > {% for business in object_list %} > {{ businessservice.service }} > {% endfor %} > > {% 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 at > http://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.
Passing a parameter into a queryset for a generic view
I want to display all the services for a particular business using the generic view "object_detail". What I would like to do is pass the value of an id from the url to the queryset (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\d+)/$', list_detail.object_detail, businessservice_list), businessservice_detail.html: {% extends "portal/base.html" %} {% block pagename %}Business Services{% endblock pagename %} {% block content %} Business Services {{ businessservice.business }} {% for business in object_list %} {{ businessservice.service }} {% endfor %} {% 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 at http://groups.google.com/group/django-users?hl=en.