Запись в бд
This commit is contained in:
1 parent
d4099e264d
commit
bc26a6a50d
4 files changed
+83
-25
No files matched your search
BIN
Binary file not shown.
+3
-1
@@ -2,6 +2,8 @@ from django.urls import path
|
|||||||
from .views import *
|
from .views import *
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path('baseCriteria/', BaseCriteriaAPI.as_view(), name='baseCriteria'),
|
||||||
|
path('userComment/', UserCommentAPI.as_view(), name='userComment'),
|
||||||
path('formfeed/', FormFeedAPI.as_view(), name='form'),
|
path('formfeed/', FormFeedAPI.as_view(), name='form'),
|
||||||
path('comment/', CommentAPI.as_view(), name='comment'),
|
path('formupdate/', FormUpdateAPI.as_view(), name='formupdate'),
|
||||||
]
|
]
|
||||||
+41
-7
@@ -1,6 +1,6 @@
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from rest_framework.generics import ListCreateAPIView
|
from rest_framework.generics import *
|
||||||
from django.forms.models import model_to_dict
|
from django.forms.models import model_to_dict
|
||||||
from accounts.models import User
|
from accounts.models import User
|
||||||
|
|
||||||
@@ -9,7 +9,31 @@ import datetime
|
|||||||
from .serializers import *
|
from .serializers import *
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
class FormFeedAPI(LinkAPIView):
|
class BaseCriteriaAPI(ListAPIView):
|
||||||
|
queryset = BaseCriteria.objects.all()
|
||||||
|
serializer_class = BaseCriteriaSerializer
|
||||||
|
|
||||||
|
class UserCommentAPI(ListCreateAPIView):
|
||||||
|
serializer_class = UserCommentSerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
queryset = UserComment.objects.filter(user_id=self.request.user.id, time_create__contains=datetime.date.today())
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
def perform_create(self, serializer):
|
||||||
|
serializer.save(user_id=self.request.user.id, comment=self.request.data['comment']) # updated after feedback
|
||||||
|
|
||||||
|
# class UserCommentUpdateAPI(UpdateAPIView):
|
||||||
|
# queryset = UserComment.objects.all()
|
||||||
|
# serializer_class = UserCommentSerializer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class FormFeedAPI(ListCreateAPIView):
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
serializer_class1 = BaseCriteriaSerializer
|
serializer_class1 = BaseCriteriaSerializer
|
||||||
serializer_class2 = UserCommentSerializer
|
serializer_class2 = UserCommentSerializer
|
||||||
@@ -19,13 +43,23 @@ class FormFeedAPI(LinkAPIView):
|
|||||||
baseCriteria = serializer_class1(queryset1, many=True)
|
baseCriteria = serializer_class1(queryset1, many=True)
|
||||||
userComment = serializer_class2(queryset2, many=True)
|
userComment = serializer_class2(queryset2, many=True)
|
||||||
return Response({'baseCriteria':baseCriteria.data, 'userComment':userComment.data})
|
return Response({'baseCriteria':baseCriteria.data, 'userComment':userComment.data})
|
||||||
|
|
||||||
class CommentAPI(ListCreateAPIView):
|
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
comid = UserComment.objects.create(user_id = request.user.id, comment = request.data['comment'])
|
comid = UserComment.objects.update_or_create(user_id = request.user.id, comment = request.data['comment'])
|
||||||
for x in request.data['ratingstatus']:
|
for x in request.data['ratingstatus']:
|
||||||
RatingStatus.objects.create(crit_id=x['id'], rating = x['rating'], usercom_id= comid.id)
|
RatingStatus.objects.update_or_create(crit_id=x['id'], rating = x['rating'], usercom_id= comid.id)
|
||||||
return Response(print('Запись создана в таблицу feedback_usercomment'))
|
return Response(print('Запись создана в таблицу feedback_usercomment'))
|
||||||
|
|
||||||
|
class FormUpdateAPI(UpdateAPIView):
|
||||||
|
|
||||||
|
def put(self, request):
|
||||||
|
print(request.data, 'pr------------------------------------ovetka')
|
||||||
|
|
||||||
|
return Response(print('Запись в таблице feedback_usercomment обновлена'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -7,12 +7,12 @@
|
|||||||
<v-container>
|
<v-container>
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col class="flex-grow-0 py-0 text-no-wrap align-self-center text-button">
|
<v-col class="flex-grow-0 py-0 text-no-wrap align-self-center text-button">
|
||||||
Оцените сайт
|
Оцените сайт
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-divider/>
|
<v-divider/>
|
||||||
</v-row>
|
</v-row>
|
||||||
<v-row
|
<v-row
|
||||||
v-for="(x, key) in tab_baseCriteria"
|
v-for="(x, key) in t_baseCriteria"
|
||||||
:key = key
|
:key = key
|
||||||
>
|
>
|
||||||
<v-col class="flex-grow-0 pb-0">
|
<v-col class="flex-grow-0 pb-0">
|
||||||
@@ -52,6 +52,7 @@
|
|||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions class="pt-0">
|
<v-card-actions class="pt-0">
|
||||||
<small v-if="average < 5 || comment.length > 0" class="pl-5">
|
<small v-if="average < 5 || comment.length > 0" class="pl-5">
|
||||||
|
|
||||||
Вы оценили сайт на <span class="font-weight-black">{{average}}</span> {{myLabel()}}
|
Вы оценили сайт на <span class="font-weight-black">{{average}}</span> {{myLabel()}}
|
||||||
</small>
|
</small>
|
||||||
<v-spacer/>
|
<v-spacer/>
|
||||||
@@ -74,7 +75,7 @@
|
|||||||
color="blue-darken-1"
|
color="blue-darken-1"
|
||||||
variant="text"
|
variant="text"
|
||||||
text="Обновить"
|
text="Обновить"
|
||||||
@click="feedAll"
|
@click="proba"
|
||||||
/>
|
/>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
@@ -94,30 +95,43 @@ export default {
|
|||||||
|
|
||||||
setup(props, context) {
|
setup(props, context) {
|
||||||
const comment = ref("")
|
const comment = ref("")
|
||||||
const tab_baseCriteria = ref([])
|
const t_baseCriteria = ref([])
|
||||||
const tab_userComment = ref([])
|
const tab_userComment = ref([])
|
||||||
|
const t_userComment = ref([])
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
axiosApiInstance.get('api/feedback/formfeed/')
|
|
||||||
.then(data => {
|
axiosApiInstance.get('api/feedback/baseCriteria/')
|
||||||
tab_baseCriteria.value = data.data.baseCriteria
|
.then(data => {
|
||||||
tab_userComment.value = data.data.userComment
|
t_baseCriteria.value = data.data.results
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
axiosApiInstance.get(`api/feedback/userComment/`)
|
||||||
|
.then(data => {
|
||||||
|
t_userComment.value = data.data.results
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function feedAll() {
|
function feedAll() {
|
||||||
const feedObj = {}
|
const feedObj = {}
|
||||||
// feedObj.ratingstatus = ratingStatus.value.decFeed
|
feedObj.ratingstatus = ratingStatus.value.decFeed
|
||||||
feedObj.comment = comment.value
|
feedObj.comment = comment.value
|
||||||
axiosApiInstance.post('api/feedback/comment/', feedObj)
|
axiosApiInstance.post('api/feedback/formfeed/', feedObj)
|
||||||
comment.value=""
|
comment.value=""
|
||||||
tab_baseCriteria.value.map(e=>e.rating=5)
|
t_baseCriteria.value.map(e=>e.rating=5)
|
||||||
|
}
|
||||||
|
|
||||||
|
function feedUp() {
|
||||||
|
const feedObj = {}
|
||||||
|
feedObj.comment = comment.value
|
||||||
|
feedObj.ratingstatus = ratingStatus.value.decFeed
|
||||||
|
axiosApiInstance.put('api/feedback/formupdate/', feedObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
const ratingStatus = computed(() => {
|
const ratingStatus = computed(() => {
|
||||||
const decFeed = []
|
const decFeed = []
|
||||||
tab_baseCriteria.value.map(e =>
|
t_baseCriteria.value.map(e =>
|
||||||
{
|
{
|
||||||
const { id, rating } = {...e}
|
const { id, rating } = {...e}
|
||||||
decFeed.push({id:id, rating:rating})
|
decFeed.push({id:id, rating:rating})
|
||||||
@@ -126,8 +140,8 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const average = computed(()=> {
|
const average = computed(()=> {
|
||||||
const sum = tab_baseCriteria.value.reduce((total, obj)=> total + obj.rating, 0)
|
const sum = t_baseCriteria.value.reduce((total, obj)=> total + obj.rating, 0)
|
||||||
const sumlen = sum/tab_baseCriteria.value.length
|
const sumlen = sum/t_baseCriteria.value.length
|
||||||
const ukr = Number.isInteger(sumlen)?sumlen:sumlen.toFixed(1)
|
const ukr = Number.isInteger(sumlen)?sumlen:sumlen.toFixed(1)
|
||||||
return ukr
|
return ukr
|
||||||
})
|
})
|
||||||
@@ -149,7 +163,15 @@ export default {
|
|||||||
context.emit('menusClose')
|
context.emit('menusClose')
|
||||||
}
|
}
|
||||||
|
|
||||||
return {tab_baseCriteria, tab_userComment, comment, average, feedAll, menusCloses, myLabel}
|
function proba() {
|
||||||
|
const feedObj = {}
|
||||||
|
|
||||||
|
feedObj.comment = comment.value
|
||||||
|
axiosApiInstance.post(`api/feedback/userComment/`, feedObj)
|
||||||
|
// console.log(t_userComment.value, 't_userComment.value');
|
||||||
|
}
|
||||||
|
|
||||||
|
return {t_baseCriteria, tab_userComment, comment, average, feedAll, feedUp, menusCloses, myLabel, proba}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user