alias51
alias51

Reputation: 8648

How to pass a variable in the URL in class based views

I have the following event feed (using Django-ical)

class EventFeed(ICalFeed):

    def items(self):
        meeting_id = self.kwargs['meeting_id']
        return Meeting.objects.get(id=meeting_id)

I am trying to pass the meeting_id through the URL conf like so:

url(r'^meetings/(?P<meeting_id>\d+)/$', EventFeed()),

However this returns 'EventFeed' object has no attribute 'kwargs'?

Upvotes: 0

Views: 416

Answers (1)

alias51
alias51

Reputation: 8648

As Daniel points out in the comments, this is a syndication framework. Therefore we need to use get_object, and to filter not get on the Meeting object:

class EventFeed(ICalFeed):

    def get_object(self, request, *args, **kwargs):
        return int(kwargs['meeting_id'])

    def items(self, meeting_id):
        return Meeting.objects.filter(id=meeting_id)

Upvotes: 1

Related Questions