Re: Output category name in a generic view
On 9/24/06, Alfonso <[EMAIL PROTECTED]> wrote: > > Thanks Jay but for some reason django doesn't like that - nothing is > output in the view?? Do you have objects in the database? And I just noticed that you were using .get(pk=1). You should be using .all(). .get() returns a single instance, but object_list expects, well, a list :) > While I'm here - if I get that to work how would I take that one step > further and output that categories cescription text - does it make a > huge difference if the dict reads: > > ammonite_dict = { > 'queryset': Category.objects.get(pk=1), > 'allow_empty': 'true', > } > > or > > ammonite_dict = { > 'queryset': Product.objects.filter(categories=1), > 'allow_empty': 'true', > } > Not sure, without seeing your models. You can always follow relationships though, even in templates. Jay P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Output category name in a generic view
Thanks Jay but for some reason django doesn't like that - nothing is output in the view?? While I'm here - if I get that to work how would I take that one step further and output that categories cescription text - does it make a huge difference if the dict reads: ammonite_dict = { 'queryset': Category.objects.get(pk=1), 'allow_empty': 'true', } or ammonite_dict = { 'queryset': Product.objects.filter(categories=1), 'allow_empty': 'true', } I think I've messed up a few things along the way because django is behaving strangely Cheers, Allan Jay Parlar wrote: > On 9/24/06, Alfonso <[EMAIL PROTECTED]> wrote: > > > > If I have a dict in my urls.py set up to obtain all products in a > > category like this: > > > > ammonite_dict = { > > 'queryset': Category.objects.get(pk=1), > > 'allow_empty': 'true', > > } > > > > and then use a generic view to map that url: > > > > (r'^glassware/ammonite/$', > > 'django.views.generic.list_detail.object_list', dict(ammonite_dict, > > template_object_name="products", > > template_name="products/products_list.html")), > > > > so (a simplified) products_list looks like this: > > > > {% extends "base.html" %} > > {% block title %}Glassware{% endblock %} > > {% block content %} > > {% for object in object_list %} > > {{ object }} > > {% endfor %} > > {% endblock %} > > > > Which all works fine, I get a nice list of products in that category - > > problems occur when I want to dynamically add the category title or > > description etc. Is there an easy way to do it using generic views? > > Yep, you can use 'extra_context', like this: > > (r'^glassware/ammonite/$', > 'django.views.generic.list_detail.object_list', dict(ammonite_dict, > template_object_name="products", > template_name="products/products_list.html", > extra_context={"title":"Glassware"})), > > Then in the template, you can have > {% block title %}{{title}}{% endblock %} > > If you look at the documentation, I think just about every generic > view can take 'extra_context'. > > Jay P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Output category name in a generic view
On 9/24/06, Alfonso <[EMAIL PROTECTED]> wrote: > > If I have a dict in my urls.py set up to obtain all products in a > category like this: > > ammonite_dict = { > 'queryset': Category.objects.get(pk=1), > 'allow_empty': 'true', > } > > and then use a generic view to map that url: > > (r'^glassware/ammonite/$', > 'django.views.generic.list_detail.object_list', dict(ammonite_dict, > template_object_name="products", > template_name="products/products_list.html")), > > so (a simplified) products_list looks like this: > > {% extends "base.html" %} > {% block title %}Glassware{% endblock %} > {% block content %} > {% for object in object_list %} > {{ object }} > {% endfor %} > {% endblock %} > > Which all works fine, I get a nice list of products in that category - > problems occur when I want to dynamically add the category title or > description etc. Is there an easy way to do it using generic views? Yep, you can use 'extra_context', like this: (r'^glassware/ammonite/$', 'django.views.generic.list_detail.object_list', dict(ammonite_dict, template_object_name="products", template_name="products/products_list.html", extra_context={"title":"Glassware"})), Then in the template, you can have {% block title %}{{title}}{% endblock %} If you look at the documentation, I think just about every generic view can take 'extra_context'. Jay P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Output category name in a generic view
If I have a dict in my urls.py set up to obtain all products in a category like this: ammonite_dict = { 'queryset': Category.objects.get(pk=1), 'allow_empty': 'true', } and then use a generic view to map that url: (r'^glassware/ammonite/$', 'django.views.generic.list_detail.object_list', dict(ammonite_dict, template_object_name="products", template_name="products/products_list.html")), so (a simplified) products_list looks like this: {% extends "base.html" %} {% block title %}Glassware{% endblock %} {% block content %} {% for object in object_list %} {{ object }} {% endfor %} {% endblock %} Which all works fine, I get a nice list of products in that category - problems occur when I want to dynamically add the category title or description etc. Is there an easy way to do it using generic views? Many Thanks Allan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---