tags:

views:

20

answers:

1

Hi, I'm struggling with something that I am sure has a very simple method, but I am not getting it right. I am trying to pass a value from the urlconf to the feeds.py file. What I am trying to do is generate specific feeds for comments on a page.

I have been reading the example in the documentation:

http://docs.djangoproject.com/en/dev/ref/contrib/syndication/

of how to use the get_object() method, but I cannot seem to pass the right values.

Here is what I have been trying. In the url.py file:

    ('^post/(?P<sl>.*)/comment_feed/$', CommentFeed()),

And in the feeds.py file:

class CommentFeed(Feed):
def get_object(self, request, sl):
    return get_object_or_404(Post, ????)

And I keep getting a ValueError saying:

invalid literal for int() with base 10: 'Test-1'

What is the right way to pass the object to the feeds CommnetFeed class?

+1  A: 

Looks like you were testing it with post/Test-1/comment_feed/ - were you?

Django expects an integer as the post id. Give it a number as in post/12/comment_feed/ and use pk=sl as done in the example given in the linked page.

return get_object_or_404(Post, pk=sl)
Amarghosh
Thank you, I got it working. Is there no way to pass a string. What I was hoping was to have:site.com/post/post_stringand then usesite.com/post/post_string/comment_feeds/Is there no way to do that?
Vernon
@Vernon You can do that if the primary key of `Post` is a string.
Amarghosh