prije restarta
This commit is contained in:
parent
6e89ea4000
commit
9908fcad02
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -18,10 +18,16 @@ class ObjektSigurnosti(models.Model):
|
|||||||
return self.naziv
|
return self.naziv
|
||||||
|
|
||||||
# class Log(models.Model):
|
# class Log(models.Model):
|
||||||
# user = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
||||||
# akcija = models.CharField(max_length=255)
|
# AKCIJA_CHOICES = (
|
||||||
|
# ('Brisanje', 'Brisanje'),
|
||||||
|
# ('Unos', 'Unos'),
|
||||||
|
# ('Uređivanje', 'Uređivanje')
|
||||||
|
# )
|
||||||
|
# user = models.ForeignKey("user.User", null=True, related_name='user_logs', on_delete=models.SET_NULL)
|
||||||
|
# timestamp = models.DateTimeField(auto_now_add=True)
|
||||||
|
# akcija = models.CharField(max_length=255, choices=AKCIJA_CHOICES)
|
||||||
# opis = models.TextField()
|
# opis = models.TextField()
|
||||||
# vrijeme = models.DateTimeField(default=timezone.now)
|
|
||||||
|
|
||||||
# def __str__(self):
|
# def __str__(self):
|
||||||
# return f"{self.user.username} - {self.akcija} - {self.opis}"
|
# return self.opis
|
||||||
@ -1,9 +1,15 @@
|
|||||||
# serializers.py
|
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from .models import ObjektSigurnosti
|
from .models import ObjektSigurnosti, Log
|
||||||
|
|
||||||
class ObjektSigurnostiSerializer(serializers.ModelSerializer):
|
class ObjektSigurnostiSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ObjektSigurnosti
|
model = ObjektSigurnosti
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
# class LogSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
# user_full_name = serializers.ReadOnlyField(source='user.full_name')
|
||||||
|
|
||||||
|
# class Meta:
|
||||||
|
# model = Log
|
||||||
|
# fields = ('id', 'user', 'user_full_name', 'timestamp', 'akcija', 'opis')
|
||||||
@ -1,8 +1,10 @@
|
|||||||
|
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from .views import ObjektSigurnostiList, ObjektSigurnostiDetail
|
from .views import ObjektSigurnostiList, ObjektSigurnostiDetail, Log
|
||||||
|
from plovidba_aplikacija import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('objekti/', ObjektSigurnostiList.as_view(), name='objektisigurnosti-list'),
|
path('objekti/', ObjektSigurnostiList.as_view(), name='objektisigurnosti-list'),
|
||||||
path('objekti/<int:pk>/', ObjektSigurnostiDetail.as_view(), name='objektisigurnosti-detail' ),
|
path('objekti/<int:pk>/', ObjektSigurnostiDetail.as_view(), name='objektisigurnosti-detail' ),
|
||||||
|
# path('logs/', views.Log.as_view(), name='log-list')
|
||||||
]
|
]
|
||||||
|
|||||||
@ -4,31 +4,43 @@ from rest_framework.generics import ListAPIView
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework import generics
|
from rest_framework import generics
|
||||||
from .models import ObjektSigurnosti
|
from .models import ObjektSigurnosti, Log
|
||||||
from .serializers import ObjektSigurnostiSerializer
|
from .serializers import ObjektSigurnostiSerializer
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from rest_framework.pagination import LimitOffsetPagination
|
from rest_framework.pagination import LimitOffsetPagination
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CustomObjektSigurnostiPagination(LimitOffsetPagination):
|
class CustomObjektSigurnostiPagination(LimitOffsetPagination):
|
||||||
default_limit = 20
|
default_limit = 20
|
||||||
|
|
||||||
|
|
||||||
class ObjektSigurnostiList(generics.ListCreateAPIView):
|
class ObjektSigurnostiList(generics.ListCreateAPIView):
|
||||||
|
queryset = ObjektSigurnosti.objects.all().order_by("naziv")
|
||||||
serializer_class = ObjektSigurnostiSerializer
|
serializer_class = ObjektSigurnostiSerializer
|
||||||
pagination_class = CustomObjektSigurnostiPagination
|
pagination_class = CustomObjektSigurnostiPagination
|
||||||
|
|
||||||
def get_queryset(self): #queryset je data iz database, listing and creating objects
|
def get_queryset(self):
|
||||||
queryset = ObjektSigurnosti.objects.all()
|
user = self.request.user
|
||||||
location = self.request.query_params.get('lokacija')
|
return user.accounts.all()
|
||||||
if location is not None:
|
# def get_queryset(self): #queryset je data iz database, listing and creating objects
|
||||||
queryset = queryset.filter(lokacija__icontains=location)
|
# queryset = ObjektSigurnosti.objects.all()
|
||||||
return queryset
|
# location = self.request.query_params.get('lokacija')
|
||||||
|
# if location is not None:
|
||||||
|
# queryset = queryset.filter(lokacija__icontains=location)
|
||||||
|
# return queryset
|
||||||
|
|
||||||
# def get_serializer_class(self):
|
def perform_create(self, serializer):
|
||||||
# if self.request.method == "GET":
|
#used to customize the behavior when creating an object, and in this case,
|
||||||
# return ObjektSigurnostiSerializer
|
#it sets the operater field and creates a log entry for the created object.
|
||||||
# return self.serializer_class()
|
serializer.save(operater=self.request.user)
|
||||||
|
instance = serializer.instance
|
||||||
|
self.create_log(instance)
|
||||||
|
|
||||||
|
def get_serializer_class(self):
|
||||||
|
if self.request.method == "GET":
|
||||||
|
return ObjektSigurnostiSerializer
|
||||||
|
return self.serializer_class()
|
||||||
|
|
||||||
|
|
||||||
class ObjektSigurnostiDetail(generics.RetrieveUpdateDestroyAPIView): #retrieving, updating, and deleting a specific object
|
class ObjektSigurnostiDetail(generics.RetrieveUpdateDestroyAPIView): #retrieving, updating, and deleting a specific object
|
||||||
@ -48,3 +60,4 @@ class ObjektSigurnostiDetail(generics.RetrieveUpdateDestroyAPIView): #ret
|
|||||||
# instance.vrsta.naziv, instance.id
|
# instance.vrsta.naziv, instance.id
|
||||||
# )
|
# )
|
||||||
# Log.objects.create(user=self.request.user, akcija="Brisanje", opis=opis)
|
# Log.objects.create(user=self.request.user, akcija="Brisanje", opis=opis)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user