...
permission_classes(permissions.IsAuthenticatedOrReadOnly,)
...
from app.serializer import ProjectSerializer
from app.models import Project
from django.shortcuts import render
from django.contrib.auth.models import User
from rest_framework import viewsets
class ProjectViewSet(viewsets.ModelViewSet):
"""
This viewset automatically provides
- 'list'
- 'create'
- 'retrieve'
- 'update'
- 'delete'
actions.
"""
queryset = Project.objects.all()
serializer_class = ProjectSerializer
permission_classes = (IsOwner,)
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
from rest_framework import permissions
class IsOwner(permissions.BasePermissions):
"""
Custom permission to only allow owner of object to
read/write it.
"""
def has_object_permissions(self, request, view, obj):
# Read and write permissions are allowed to owner.
return obj.owner == request.user
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
| Filipe Ximenes +55 (81) 8245-9204 Vinta Software Studio http://www.vinta.com.br |
from django.shortcuts import render, get_object_or_404
from setup.permissions import IsOwnerOrReadOnly, IsOwner, IsReadOnly
from rest_framework import permissions
from setup.models import Project
class ProjectViewSet(viewsets.ModelViewSet):
"""
This vieset automatically provides 'list', 'create', 'retrieve',
'update' and 'destroy' actions.
"""
queryset = Project.objects.all()
serializer_class = ProjectSerializer
permission_classes = (permissions.IsAuthenticated,
IsOwner,
)
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
def get_object(self):
obj = get_object_or_404(self.get_queryset())
self.check_object_permissions(self.request, obj)
return obj
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def has_object_permission(self, request, view, obj):
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alright. First thing I found: the correct method to overwrite when creating a custom permission is:def has_object_permission(self, request, view, obj):
and not "has_object_permissions" (with an 's' in the end) as you are doing in the project. Fix this and tell me if things work. =)
On Wed, Apr 8, 2015 at 6:03 AM, <juefri...@gmail.com> wrote:
Hej Filipe!Sorry for my late Answer!Yes... You can have my Project of Course!I removed dp.sqlite3 and virtualenv .. .you might install missing dependencies, and run the
- python manage.py migrate
- python manage.py createsuperuser
- ...
Thx for your support!
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.