28 lines
886 B
Python
28 lines
886 B
Python
from django.shortcuts import render
|
|
from django.core import serializers
|
|
from rest_framework.decorators import api_view, permission_classes
|
|
|
|
# Create your views here.
|
|
from rest_framework import viewsets
|
|
from rest_framework.response import Response
|
|
from rest_framework.permissions import IsAuthenticatedOrReadOnly, IsAuthenticated
|
|
|
|
from companies.models import Company
|
|
from companies.serializers import CompanySerializer
|
|
|
|
from back_latienda.permissions import IsCreator
|
|
|
|
|
|
class CompanyViewSet(viewsets.ModelViewSet):
|
|
queryset = Company.objects.all()
|
|
serializer_class = CompanySerializer
|
|
permission_classes = [IsAuthenticatedOrReadOnly, IsCreator]
|
|
|
|
|
|
@api_view(['GET',])
|
|
@permission_classes([IsAuthenticated,])
|
|
def my_company(request):
|
|
qs = Company.objects.filter(creator=request.user)
|
|
data = serializers.serialize('json', qs)
|
|
return Response(data=data)
|