Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
urls.py generic views and foreign keys
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David  
View profile  
 More options Nov 5, 2:34 am
From: David <cthl...@googlemail.com>
Date: Wed, 4 Nov 2009 07:34:41 -0800 (PST)
Local: Thurs, Nov 5 2009 2:34 am
Subject: urls.py generic views and foreign keys
Hello

I have just started to learn Django.

I have setup a Blog model, and an Entry model. I would like to use a
generic view to list all of the entries in a given blog. The url to
this should be /blog-slug/.

I am unclear how I can bring up all of the entries for my blog, or
rather how I can pass "blog.slug" into the Entry.objects.all() so it
will pick up all the correct entries for referenced blog.

I think I should be using select_related, but I don't know how to pass
the blog.slug to it. So far I am just getting:

object_list() got an unexpected keyword argument 'slug'

My urls.py looks like this:

from django.conf.urls.defaults import *
from bandsite.blogs.models import Blog
from bandsite.blogs.models import Entry

entry_list = {
    'queryset': Entry.objects.all(),
    'template_object_name': 'entry',

}

urlpatterns = patterns('',
                       (r'^(?P<slug>[-\w]+)/$',
'django.views.generic.list_detail.object_list', entry_list),
)

Thank you for any help you can offer me.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Roseman  
View profile  
 More options Nov 5, 3:12 am
From: Daniel Roseman <dan...@roseman.org.uk>
Date: Wed, 4 Nov 2009 08:12:42 -0800 (PST)
Local: Thurs, Nov 5 2009 3:12 am
Subject: Re: urls.py generic views and foreign keys
On Nov 4, 3:34 pm, David <cthl...@googlemail.com> wrote:

You can't do this directly with the generic view - you'll need to wrap
it. See the documentation here:
http://docs.djangoproject.com/en/dev/topics/generic-views/#complex-fi...
which has a very similar example to what you want to do.
--
DR.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David  
View profile  
 More options Nov 5, 4:23 am
From: David <cthl...@googlemail.com>
Date: Wed, 4 Nov 2009 09:23:45 -0800 (PST)
Local: Thurs, Nov 5 2009 4:23 am
Subject: Re: urls.py generic views and foreign keys
Thank you Daniel, that worked perfectly.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google