from django.shortcuts import render
from rest_framework import generics
from .models import Company
from .serializers import CompanySerializer
class CompanyList(generics.ListCreateAPIView):
queryset = Company.objects.all()
serializer_class = CompanySerializer
from rest_framework import serializers
from .models import Company
class CompanySerializer(serializers.ModelSerializer):
class Meta:
model = Company
fields = '__all__'
from django.shortcuts import render
from rest_framework import generics
from .models import Company
from .serializers import CompanySerializer
class CompanyList(generics.ListCreateAPIView):
queryset = Company.objects.all()
serializer_class = CompanySerializer
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
],
'DEFAULT_PARSER_CLASSES': [
'rest_framework.parsers.JSONParser',
]
}
class CompanyList(generics.ListCreateAPIView):
queryset = Company.objects.all()
serializer_class = CompanySerializer
def get_queryset(self):
"""
Фильтруем компании по пользователю который отправил запрос
"""
user = self.request.user
return Company.objects.filter(user=user)