2014-05-08 16:59:35 +00:00
|
|
|
from rest_framework import viewsets
|
|
|
|
|
|
|
|
from orchestra.api import router
|
|
|
|
|
|
|
|
from .models import Account
|
|
|
|
from .serializers import AccountSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class AccountApiMixin(object):
|
|
|
|
def get_queryset(self):
|
|
|
|
qs = super(AccountApiMixin, self).get_queryset()
|
2014-09-29 13:34:38 +00:00
|
|
|
return qs.filter(account=self.request.user.pk)
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AccountViewSet(viewsets.ModelViewSet):
|
|
|
|
model = Account
|
|
|
|
serializer_class = AccountSerializer
|
2014-09-29 13:34:38 +00:00
|
|
|
singleton_pk = lambda _,request: request.user.pk
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
qs = super(AccountViewSet, self).get_queryset()
|
2014-09-30 16:39:47 +00:00
|
|
|
return qs.filter(id=self.request.user.pk)
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
router.register(r'accounts', AccountViewSet)
|