Created
November 30, 2010 20:18
-
-
Save bohde/722318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EntryResource(ModelResource): | |
user = fields.ForeignKey(UserResource, 'user') | |
class Meta: | |
queryset = Entry.objects.all() | |
resource_name = 'entry' | |
def dispatch(self, request_type, request, **kwargs): | |
username = kwargs.pop('username') | |
kwargs['user'] = get_object_or_404(User, username=username) | |
return super(EntryResource, self).dispatch(request_type, request, **kwargs) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# urls.py | |
from django.conf.urls.defaults import * | |
from myapp.api import EntryResource | |
entry_resource = EntryResource() | |
urlpatterns = patterns('', | |
# The normal jazz here... | |
(r'^blog/', include('myapp.urls')), | |
(r'^api/(?P<username>\w+)/', include(entry_resource.urls)), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment