Skip to content

Instantly share code, notes, and snippets.

@omarish
Created August 9, 2012 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omarish/3299867 to your computer and use it in GitHub Desktop.
Save omarish/3299867 to your computer and use it in GitHub Desktop.
#
# Urls
#
from django.conf.urls.defaults import patterns, url, include
from django.contrib import admin
from tastypie.api import Api
from resources import UserResource, FollowResource, FollowItemResource
admin.autodiscover()
v1_api = Api("v1_api")
v1_api.register(UserResource())
v1_api.register(FollowResource())
urlpatterns = patterns('pricer.me.views',
url(r'', include(v1_api.urls)),
url(r'^backbone/$', 'following_list_backbone', name="feed_backbone"),
url(r'^$', 'following_list', name="feed")
)
#
# Resources
#
from tastypie import fields
from tastypie.resources import ModelResource
from tastypie.authorization import Authorization
from django.contrib.auth.models import User
from models import Follow, FollowItem
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
excludes = ['email', 'password', 'is_active', 'is_staff', 'is_superuser']
class FollowResource(ModelResource):
class Meta:
queryset = Follow.objects.all()
# authorization = Authorization()
resource_name = 'follow'
list_allowed_methods = ['get', 'post']
detail_allowed_methods = ['get']
include_resource_uri = True
class FollowItemResource(ModelResource):
user = fields.ForeignKey(UserResource, 'user')
follow = fields.ForeignKey(FollowResource, 'follow')
class Meta:
queryset = FollowItem.objects.all()
authorization = Authorization()
resource_name = 'followItem'
list_allowed_methods = ['get', 'post']
detail_allowed_methods = ['get']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment