Commit 24635c2c authored by Rafal's avatar Rafal

add userview, serializer

parent eb2fff27
...@@ -13,6 +13,7 @@ router.register(r'beacon_managers', hub_views.BeaconManagerViewSet) ...@@ -13,6 +13,7 @@ router.register(r'beacon_managers', hub_views.BeaconManagerViewSet)
router.register(r'category', hub_views.CategoryViewSet) router.register(r'category', hub_views.CategoryViewSet)
router.register(r'sites', hub_views.SiteViewSet) router.register(r'sites', hub_views.SiteViewSet)
router.register(r'uuid', hub_views.UuidBeaconViewSet) router.register(r'uuid', hub_views.UuidBeaconViewSet)
router.register(r'users', hub_views.UserViewSet)
urlpatterns = patterns('', urlpatterns = patterns('',
......
from rest_framework import serializers from rest_framework import serializers
from rest_framework.decorators import detail_route, list_route from django.contrib.auth.models import User
from Hub.models import Beacon, BeaconManager, Category, Site from Hub.models import Beacon, BeaconManager, Category, Site
class SiteSerializer(serializers.HyperlinkedModelSerializer): class SiteSerializer(serializers.HyperlinkedModelSerializer):
author = serializers.HyperlinkedRelatedField(view_name='user-detail', queryset=User.objects.all())
class Meta: class Meta:
model = Site model = Site
fields = ('id', 'url', 'link_url', 'description', 'category' 'author') fields = ('id', 'url', 'link_url', 'description', 'category', 'author')
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Site
fields = ('id', 'url')
class BeaconSerializer(serializers.HyperlinkedModelSerializer): class BeaconSerializer(serializers.HyperlinkedModelSerializer):
......
from django.contrib import auth from django.contrib import auth
from django.contrib.auth import login from django.contrib.auth import login
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponseRedirect, HttpResponse from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render, render_to_response, redirect from django.shortcuts import render, render_to_response, redirect
...@@ -11,7 +12,8 @@ import rest_framework ...@@ -11,7 +12,8 @@ import rest_framework
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
from Hub.models import Beacon, BeaconManager, Site, Category from Hub.models import Beacon, BeaconManager, Site, Category
from Hub.serializers import BeaconSerializer, BeaconManagerSerializer, SiteSerializer, CategorySerializer from Hub.serializers import BeaconSerializer, BeaconManagerSerializer, SiteSerializer, CategorySerializer, \
UserSerializer
class BeaconViewSet(viewsets.ModelViewSet): class BeaconViewSet(viewsets.ModelViewSet):
...@@ -21,6 +23,14 @@ class BeaconViewSet(viewsets.ModelViewSet): ...@@ -21,6 +23,14 @@ class BeaconViewSet(viewsets.ModelViewSet):
queryset = Beacon.objects.all() queryset = Beacon.objects.all()
serializer_class = BeaconSerializer serializer_class = BeaconSerializer
class UserViewSet(viewsets.ModelViewSet):
"""
API for places
"""
queryset = User.objects.all()
serializer_class = UserSerializer
class BeaconManagerViewSet(viewsets.ModelViewSet): class BeaconManagerViewSet(viewsets.ModelViewSet):
""" """
API for places API for places
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment