Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File "/Users/bjacobel/.virtualenvs/hey/lib/python2.7/site-packages/rest_framework/fields.py", line 375, in to_representation
- raise NotImplementedError('to_representation() must be implemented.')
- from django.contrib.auth.models import User
- from rest_framework import serializers
- class UserSerializer(serializers.ModelSerializer):
- class Meta:
- model = User
- fields = ('id', 'first_name', 'last_name', 'email', 'username')
- from django.contrib.auth.models import User
- from hey.apps.api import serializers
- from rest_framework import viewsets, permissions, filters
- class User(viewsets.ModelViewSet):
- queryset = User.objects.all()
- serializer_class = serializers.UserSerializer
- permission_classes = (permissions.IsAuthenticated,)
- filter_backends = (filters.OrderingFilter,)
- from django.conf.urls import patterns, url, include
- from hey.apps.api import views
- from rest_framework.routers import SimpleRouter
- router = SimpleRouter()
- router.register(r'user', views.User)
- urlpatterns = patterns('',
- url(r'^', include(router.urls)),
- )
- from rest_framework import pagination
- from rest_framework import serializers
- class LinksSerializer(serializers.Serializer):
- next = pagination.NextPageField(source='*')
- prev = pagination.PreviousPageField(source='*')
- class CustomPaginationSerializer(pagination.BasePaginationSerializer):
- links = LinksSerializer(source='*') # Takes the page object as the source
- total_results = serializers.Field(source='paginator.count')
- results_field = 'objects'
- REST_FRAMEWORK = {
- 'DEFAULT_PAGINATION_SERIALIZER_CLASS': 'hey.apps.api.pagination.CustomPaginationSerializer',
- 'PAGINATE_BY': 20, # Default to 20
- 'PAGINATE_BY_PARAM': 'limit', # Allow client to override, using `?limit=xxx`.
- 'MAX_PAGINATE_BY': 100, # Maximum limit allowed when using `?limit=xxx`.
- 'TEST_REQUEST_DEFAULT_FORMAT': 'json',
- 'DEFAULT_AUTHENTICATION_CLASSES': (
- 'rest_framework.authentication.BasicAuthentication',
- 'rest_framework.authentication.TokenAuthentication',
- 'rest_framework.authentication.SessionAuthentication',
- )
- }
- class CustomPaginationSerializer(pagination.BasePaginationSerializer):
- links = LinksSerializer(source='*') # Takes the page object as the source
- total_results = serializers.ReadOnlyField(source='paginator.count')
- results_field = 'objects'
Add Comment
Please, Sign In to add comment