Галерея
This commit is contained in:
1 parent
be136d0f4f
commit
c23cf63f6d
7 files changed
+142
-348
No files matched your search
@@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<div class="flex-column h-100">
|
||||
|
||||
|
||||
<v-card
|
||||
:ref="i"
|
||||
class="mx-auto px-3 pt-3"
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<template>
|
||||
<v-row class="justify-center">
|
||||
|
||||
<v-col
|
||||
v-if="route.path == '/news' && 'id' in route.query?false:true"
|
||||
class="flex-column"
|
||||
lg="6"
|
||||
>
|
||||
|
||||
<div class="d-flex flex-column py-3 h-100 ">
|
||||
<v-row class=" flex-grow-1 d-flex h-0 overflow-auto">
|
||||
<v-col class="pa-0 ">
|
||||
@@ -22,6 +24,7 @@
|
||||
class="mx-auto"
|
||||
cover
|
||||
/>
|
||||
|
||||
<v-list-item class="w-100">
|
||||
<template v-slot:prepend>
|
||||
<v-avatar
|
||||
@@ -30,6 +33,7 @@
|
||||
size="25"
|
||||
>
|
||||
</v-avatar>
|
||||
|
||||
<v-list-item-title class="text-caption">{{splitname(x.author)}}</v-list-item-title>
|
||||
</template>
|
||||
<template v-slot:append>
|
||||
@@ -53,6 +57,8 @@
|
||||
|
||||
<v-card-text>
|
||||
{{x.text}}
|
||||
|
||||
|
||||
</v-card-text>
|
||||
<v-divider/>
|
||||
|
||||
@@ -175,6 +181,13 @@
|
||||
<v-card-title class="pt-0 pb-1">
|
||||
{{x.title}}
|
||||
</v-card-title>
|
||||
<v-switch
|
||||
v-model="gallery"
|
||||
|
||||
|
||||
></v-switch>
|
||||
|
||||
|
||||
<v-img
|
||||
:src="`${burl}${x.link}`"
|
||||
height="350px"
|
||||
@@ -214,6 +227,66 @@
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-divider/>
|
||||
<v-row class="ma-0 my-3 overflow-auto h-0" v-if="!gallery">
|
||||
<v-col class="pa-0">
|
||||
<v-card-text class="pt-0">
|
||||
|
||||
<div v-html=formatText(x.text)>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</v-card-text>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
<v-row class="ma-0 my-3 overflow-auto h-0" v-else>
|
||||
<v-col>
|
||||
<v-row>
|
||||
<v-col
|
||||
v-for="n in x.gallery"
|
||||
:key="n"
|
||||
class="d-flex child-flex"
|
||||
cols="4"
|
||||
>
|
||||
<v-img
|
||||
:src="`${burl}${n.img}`"
|
||||
:lazy-src="`${burl}${n.img}`"
|
||||
aspect-ratio="1"
|
||||
cover
|
||||
class="bg-grey-lighten-2"
|
||||
>
|
||||
<!-- <template v-slot:placeholder>
|
||||
<v-row
|
||||
class="fill-height ma-0"
|
||||
align="center"
|
||||
justify="center"
|
||||
>
|
||||
<v-progress-circular
|
||||
indeterminate
|
||||
color="grey-lighten-5"
|
||||
></v-progress-circular>
|
||||
</v-row>
|
||||
</template> -->
|
||||
</v-img>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-col>
|
||||
<v-col class="flex-column d-flex">
|
||||
<v-row class="flex-grow-0" v-if="gallery">
|
||||
<v-col class="pb-0 ">
|
||||
<v-card
|
||||
height="350px"
|
||||
class="flex-column d-flex"
|
||||
|
||||
>
|
||||
<v-row class="ma-0 my-3 overflow-auto h-0">
|
||||
<v-col class="pa-0">
|
||||
<v-card-text class="pt-0">
|
||||
@@ -229,18 +302,6 @@
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-col>
|
||||
<v-col class="flex-column d-flex">
|
||||
<!-- <v-row class="flex-grow-0">
|
||||
<v-col class="bg-red pb-0 ">
|
||||
<v-card
|
||||
height="350px"
|
||||
|
||||
>
|
||||
1
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row> -->
|
||||
<v-row >
|
||||
<v-col class="">
|
||||
<v-card
|
||||
@@ -323,340 +384,8 @@
|
||||
</v-row>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<!-- <v-row class="justify-center">
|
||||
<v-col
|
||||
v-if="route.path == '/news' && 'id' in route.query?false:true"
|
||||
class="flex-column"
|
||||
lg="6"
|
||||
>
|
||||
<div class="d-flex flex-column py-3 h-100 ">
|
||||
<v-row class=" flex-grow-1 d-flex h-0 overflow-auto">
|
||||
<v-col class="pa-0 ">
|
||||
<v-card
|
||||
class=" rounded-0"
|
||||
v-for="(x, i) in newss.result" :key=i
|
||||
>
|
||||
<v-card-title class="pt-0 pb-1">
|
||||
{{x.title}}
|
||||
</v-card-title>
|
||||
<v-img
|
||||
:src="`${burl}${x.link}`"
|
||||
height="350px"
|
||||
width="96%"
|
||||
class="mx-auto"
|
||||
cover
|
||||
/>
|
||||
<v-list-item class="w-100">
|
||||
<template v-slot:prepend>
|
||||
<v-avatar
|
||||
color="loading_avatar"
|
||||
:image="checkremote( `${spravURL}${x.author.login}.jpg`)"
|
||||
size="25"
|
||||
>
|
||||
</v-avatar>
|
||||
<v-list-item-title class="text-caption">{{splitname(x.author)}}</v-list-item-title>
|
||||
</template>
|
||||
<template v-slot:append>
|
||||
<div class="justify-self-end">
|
||||
<v-icon class="me-1" :icon="x.scores.filter(e=> e.user==accountStore.user.login && e.score == true).length>0?'mdi-thumb-up':'mdi-thumb-up-outline'" @click="toggleIncrementLike(x.id, true)"></v-icon>
|
||||
<span class="subheading me-2">{{x.scores.filter(e=> e.score==true).length}}</span>
|
||||
<span class="me-1">·</span>
|
||||
<v-icon class="me-1" :icon="x.scores.filter(e=> e.user==accountStore.user.login && e.score == false).length>0?'mdi-thumb-down':'mdi-thumb-down-outline'" @click="toggleIncrementLike(x.id, false)"/>
|
||||
<span class="subheading me-2">{{x.scores.filter(e=> e.score==false).length}}</span>
|
||||
<span class="me-1">·</span>
|
||||
<v-icon class="me-1" icon="mdi-message-text-outline" @click="openComent(x.id)"/>
|
||||
<span @click="x.showComment=!x.showComment" class="pointer subheading">{{ x.comment.length }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</v-list-item>
|
||||
|
||||
|
||||
|
||||
<div >
|
||||
<v-divider/>
|
||||
|
||||
<v-card-text>
|
||||
{{x.text}}
|
||||
</v-card-text>
|
||||
<v-divider/>
|
||||
|
||||
<v-expand-transition>
|
||||
|
||||
<div v-show="x.showComment" v-if="x.comment.length>0">
|
||||
<div
|
||||
v-for = "(y, key) in x.comment"
|
||||
:key="key"
|
||||
class="d-flex flex-column pa-3"
|
||||
>
|
||||
|
||||
|
||||
<v-row
|
||||
class="justify-space-between ma-0 align-center bgchat mr-7"
|
||||
:class="accountStore.user.login==y.author.login?'bgchatnot':'bgchat'"
|
||||
|
||||
>
|
||||
<v-col class="flex-grow-1 text-subtitle-2 pl-2 pa-0 "
|
||||
|
||||
>
|
||||
{{ accountStore.user.login==y.author.login?'':splitname(y.author) }}
|
||||
</v-col>
|
||||
<v-col class="pa-0 text-center text-subtitle-2 ">
|
||||
|
||||
{{dateformat(y.cdate)}}
|
||||
</v-col>
|
||||
<v-col class="pa-0 pr-2 text-end text-subtitle-2 ">
|
||||
{{ accountStore.user.login!=y.author.login?'':splitname(y.author) }}
|
||||
</v-col>
|
||||
|
||||
|
||||
</v-row>
|
||||
|
||||
<div class="text-subtitle-2">
|
||||
|
||||
|
||||
</div>
|
||||
<v-row>
|
||||
<v-col class="pr-0">
|
||||
<v-alert
|
||||
|
||||
|
||||
color="bg_white"
|
||||
rounded=0
|
||||
:border="accountStore.user.login==y.author.login?'end':'start'"
|
||||
:border-color="accountStore.user.login==y.author.login?'success':'deep-purple accent-4'"
|
||||
elevation=0
|
||||
>
|
||||
|
||||
{{ y.text }}
|
||||
|
||||
</v-alert>
|
||||
</v-col>
|
||||
<v-col class="flex-grow-0 d-flex pa-0 align-center"
|
||||
:class="accountStore.user.login==y.author.login?'pa-0':'pa-5'"
|
||||
>
|
||||
<v-btn
|
||||
v-if="accountStore.user.login==y.author.login"
|
||||
variant="text"
|
||||
size="small"
|
||||
icon='mdi-delete'
|
||||
color="delete_btn"
|
||||
@click="deletComment(y.id, x.id)"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</v-expand-transition>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row class="flex-grow-0" v-show="route.path == '/news' && 'id' in route.query?false:true">
|
||||
<v-col class="ma-0 pa-0 pt-2">
|
||||
<v-pagination
|
||||
v-model="page"
|
||||
:length="newss.allnews"
|
||||
prev-icon="mdi-menu-left"
|
||||
next-icon="mdi-menu-right"
|
||||
@click="pagelistNews"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col class="ma-0 flex-grow-0 mwidth mt-1 pa-0">
|
||||
<v-select
|
||||
hide-details
|
||||
density="compact"
|
||||
v-model="selecnews"
|
||||
variant="underlined"
|
||||
:items="['1', '2', '3', '4', '5', '6']"/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</v-col>
|
||||
<v-col v-else class="flex-column d-flex">
|
||||
<v-row v-for="(x, i) in newss.result" :key=i>
|
||||
<v-col class="flex-column d-flex">
|
||||
<v-row class="flex-grow-1">
|
||||
<v-col class="pr-0">
|
||||
<v-card
|
||||
class=" rounded-0 h-100"
|
||||
>
|
||||
<v-card-title class="pt-0 pb-1">
|
||||
{{x.title}}
|
||||
</v-card-title>
|
||||
<v-img
|
||||
:src="`${burl}${x.link}`"
|
||||
height="350px"
|
||||
width="96%"
|
||||
class="mx-auto"
|
||||
cover
|
||||
/>
|
||||
<v-list-item class="w-100">
|
||||
<template v-slot:prepend>
|
||||
<v-avatar
|
||||
color="loading_avatar"
|
||||
:image="checkremote( `${spravURL}${x.author.login}.jpg`)"
|
||||
size="25"
|
||||
>
|
||||
</v-avatar>
|
||||
<v-list-item-title class="text-caption">{{splitname(x.author)}}</v-list-item-title>
|
||||
</template>
|
||||
<template v-slot:append>
|
||||
<div class="justify-self-end">
|
||||
<v-icon class="me-1" :icon="x.scores.filter(e=> e.user==accountStore.user.login && e.score == true).length>0?'mdi-thumb-up':'mdi-thumb-up-outline'" @click="toggleIncrementLike(x.id, true)"></v-icon>
|
||||
<span class="subheading me-2">{{x.scores.filter(e=> e.score==true).length}}</span>
|
||||
<span class="me-1">·</span>
|
||||
<v-icon class="me-1" :icon="x.scores.filter(e=> e.user==accountStore.user.login && e.score == false).length>0?'mdi-thumb-down':'mdi-thumb-down-outline'" @click="toggleIncrementLike(x.id, false)"/>
|
||||
<span class="subheading me-2">{{x.scores.filter(e=> e.score==false).length}}</span>
|
||||
<span class="me-1">·</span>
|
||||
<v-icon class="me-1" icon="mdi-message-text-outline" @click="openComent(x.id)"/>
|
||||
<span @click="x.showComment=!x.showComment" class="pointer subheading">{{ x.comment.length }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</v-list-item>
|
||||
|
||||
<v-divider/>
|
||||
|
||||
<v-card-text class="overflow-auto heigCard">
|
||||
|
||||
{{x.text}}
|
||||
|
||||
</v-card-text>
|
||||
|
||||
|
||||
</v-card>
|
||||
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
</v-col>
|
||||
<v-col>
|
||||
<v-card >
|
||||
<div class="overflow-auto commentHeight mb-3">
|
||||
|
||||
|
||||
<div
|
||||
v-for = "(y, key) in x.comment"
|
||||
:key="key"
|
||||
class="d-flex flex-column pa-3 "
|
||||
>
|
||||
|
||||
|
||||
<v-row
|
||||
class="justify-space-between ma-0 align-center bgchat mr-7"
|
||||
:class="accountStore.user.login==y.author.login?'bgchatnot':'bgchat'"
|
||||
|
||||
>
|
||||
<v-col class="flex-grow-1 text-subtitle-2 pl-2 pa-0 "
|
||||
|
||||
>
|
||||
{{ accountStore.user.login==y.author.login?'':splitname(y.author) }}
|
||||
</v-col>
|
||||
<v-col class="pa-0 text-center text-subtitle-2 ">
|
||||
|
||||
{{dateformat(y.cdate)}}
|
||||
</v-col>
|
||||
<v-col class="pa-0 pr-2 text-end text-subtitle-2 ">
|
||||
{{ accountStore.user.login!=y.author.login?'':splitname(y.author) }}
|
||||
</v-col>
|
||||
|
||||
|
||||
</v-row>
|
||||
|
||||
<div class="text-subtitle-2">
|
||||
|
||||
|
||||
</div>
|
||||
<v-row>
|
||||
<v-col class="pr-0">
|
||||
<v-alert
|
||||
|
||||
|
||||
color="bg_white"
|
||||
rounded=0
|
||||
:border="accountStore.user.login==y.author.login?'end':'start'"
|
||||
:border-color="accountStore.user.login==y.author.login?'success':'deep-purple accent-4'"
|
||||
elevation=0
|
||||
>
|
||||
|
||||
{{ y.text }}
|
||||
|
||||
</v-alert>
|
||||
</v-col>
|
||||
<v-col class="flex-grow-0 d-flex pa-0 align-center"
|
||||
:class="accountStore.user.login==y.author.login?'pa-0':'pa-5'"
|
||||
>
|
||||
<v-btn
|
||||
v-if="accountStore.user.login==y.author.login"
|
||||
variant="text"
|
||||
size="small"
|
||||
icon='mdi-delete'
|
||||
color="delete_btn"
|
||||
@click="deletComment(y.id, x.id)"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-col>
|
||||
|
||||
<v-dialog
|
||||
v-model="dialogCommentShow"
|
||||
persistent
|
||||
width="550"
|
||||
>
|
||||
<v-card>
|
||||
<v-card-title class="text-h5">
|
||||
Прокоментировать новость
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-textarea
|
||||
variant="solo"
|
||||
hide-details
|
||||
rows="5"
|
||||
v-model="textcomment"
|
||||
|
||||
></v-textarea>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn
|
||||
color="modal_btn"
|
||||
variant="text"
|
||||
@click="dialogCommentShow = false"
|
||||
>
|
||||
Отмена
|
||||
</v-btn>
|
||||
<v-btn
|
||||
color="modal_btn"
|
||||
variant="text"
|
||||
@click="addComment"
|
||||
>
|
||||
Отправить
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-row> -->
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@@ -670,6 +399,7 @@ import { axiosApiInstance } from '@/utils/axios-api'
|
||||
import { format } from 'date-fns'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { spravURL } from '@/utils/axios-api'
|
||||
|
||||
const accountStore = useAccountStore()
|
||||
|
||||
export default {
|
||||
@@ -686,6 +416,7 @@ export default {
|
||||
|
||||
const newss=ref([])
|
||||
const dialogCommentShow = ref(false)
|
||||
const gallery = ref(false)
|
||||
const burl = baseURL.slice(0,-1)
|
||||
const textcomment = ref('')
|
||||
const idnews = ref(0)
|
||||
@@ -703,17 +434,26 @@ export default {
|
||||
|
||||
getfromserver(str, newss)
|
||||
|
||||
|
||||
|
||||
const imgGallery = () => {
|
||||
console.log(newss.value, 'ku');
|
||||
}
|
||||
|
||||
const toggleIncrementLike = (news, scores) => {
|
||||
axiosApiInstance.post(`api/navigation/news/`, {news: news, scores: scores}).then(result => {
|
||||
|
||||
newss.value.result[newss.value.result.findIndex(e=> e.id==news)].scores= result.data
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
const addComment = () => {
|
||||
axiosApiInstance.post(`api/navigation/news/`, {news: idnews.value, text: textcomment.value}).then(result => {
|
||||
console.log('----------------111111111111111111111111111111111');
|
||||
dialogCommentShow.value=!dialogCommentShow.value
|
||||
|
||||
newss.value.result[newss.value.result.findIndex(e=> e.id==result.data['news'])].comment = result.data.comment
|
||||
})
|
||||
textcomment.value=""
|
||||
@@ -721,13 +461,16 @@ export default {
|
||||
|
||||
const deletComment = (id, news) => {
|
||||
axiosApiInstance.post(`api/navigation/news/`, {delid: id, news: news}).then(result => {
|
||||
|
||||
newss.value.result[newss.value.result.findIndex(e=> e.id==result.data['news'])].comment = result.data.comment
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const pagelistNews =() => {
|
||||
|
||||
getfromserver(`api/navigation/news/?name=${route.path}&page=${page.value-1}&selected=${selecnews.value}`, newss)
|
||||
|
||||
}
|
||||
|
||||
watch(()=>route.query,(newValue,oldValue)=>{
|
||||
@@ -746,10 +489,21 @@ export default {
|
||||
|
||||
watch(()=>accountStore.cod2user ,(newValue,oldValue)=>{
|
||||
if(newValue){
|
||||
|
||||
getfromserver(`api/navigation/news/?name=${route.path}&page=${page.value-1}&selected=${selecnews.value}`,newss)
|
||||
}
|
||||
}, {deep:true})
|
||||
|
||||
// watch(()=>newss ,(newValue,oldValue)=>{
|
||||
// if(newValue){
|
||||
// console.log('111111111');
|
||||
// }
|
||||
// else {
|
||||
// console.log('2222222222222');
|
||||
// }
|
||||
// }
|
||||
// )
|
||||
|
||||
const dateformat = (datas) => {
|
||||
return format(new Date(datas), 'dd.MM.yyyy HH:mm')
|
||||
}
|
||||
@@ -803,7 +557,8 @@ export default {
|
||||
checkremote,
|
||||
route,
|
||||
spravURL,
|
||||
formatText
|
||||
formatText,
|
||||
gallery
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 578 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 116 KiB |
@@ -3,6 +3,20 @@ from django.utils.safestring import mark_safe
|
||||
|
||||
from .models import *
|
||||
|
||||
class GalleryInline(admin.TabularInline):
|
||||
model = Gallery
|
||||
fields = ( 'img', 'get_html_photo')
|
||||
readonly_fields=('get_html_photo',)
|
||||
can_delete = False
|
||||
show_change_link = False
|
||||
extra = 0
|
||||
|
||||
def get_html_photo(self, object):
|
||||
if object.img:
|
||||
return mark_safe(f"<img src='{object.img.url}' width=50>")
|
||||
|
||||
get_html_photo.short_description="Превью изображения"
|
||||
|
||||
class NewsAdmin(admin.ModelAdmin):
|
||||
list_display = ('title', 'author', 'text', 'cdate', 'link', 'get_html_photo')
|
||||
readonly_fields=('get_html_photo',)
|
||||
@@ -21,6 +35,8 @@ class NewsAdmin(admin.ModelAdmin):
|
||||
|
||||
get_html_photo.short_description="Превью изображения"
|
||||
|
||||
inlines = [GalleryInline]
|
||||
|
||||
class CarouselsAdmin(admin.ModelAdmin):
|
||||
list_display=('title', 'cdate', 'enddate', 'get_html_photo', 'link','published', 'sender', 'order')
|
||||
readonly_fields=('get_html_photo',)
|
||||
|
||||
@@ -37,19 +37,30 @@ class Links(models.Model):
|
||||
class News(models.Model):
|
||||
title=models.CharField(max_length=255, verbose_name='Заголовок')
|
||||
text= RichTextUploadingField(null=True, blank= True, verbose_name='Текст новости')
|
||||
|
||||
cdate =models.DateTimeField(auto_now_add=True, verbose_name='Дата создания')
|
||||
author = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False, on_delete=models.PROTECT, verbose_name='Автор')
|
||||
link = models.ImageField(upload_to='newsimage/%Y/%m/%d', null=True, default="newsimage/default.jpg", verbose_name='Изображение')
|
||||
|
||||
class Meta:
|
||||
|
||||
verbose_name = "Новостную ленту"
|
||||
verbose_name = "Новостная лента"
|
||||
verbose_name_plural = "Новостная лента"
|
||||
|
||||
def __str__(self):
|
||||
return str(self.title)
|
||||
|
||||
class Gallery(models.Model):
|
||||
img = models.ImageField(upload_to='newsgallery/%Y/%m/%d', null=True, verbose_name='Изображение')
|
||||
news = models.ForeignKey(News, editable=False, on_delete=models.PROTECT, related_name='get_gallery_news', verbose_name='Новость')
|
||||
|
||||
class Meta:
|
||||
|
||||
verbose_name = "Изображения к новости"
|
||||
verbose_name_plural = "Изображения к новости"
|
||||
|
||||
def __str__(self):
|
||||
return str(self.news)
|
||||
|
||||
class ScoreNews(models.Model):
|
||||
author = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False, on_delete=models.PROTECT, verbose_name='Автор')
|
||||
score = models.BooleanField(default=None, null=True, verbose_name='Оценка лайк/дизлайк')
|
||||
|
||||
@@ -9,6 +9,10 @@ class LinkSerializer(serializers.ModelSerializer):
|
||||
model = Links
|
||||
fields = '__all__'
|
||||
|
||||
class GallerySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Gallery
|
||||
fields = '__all__'
|
||||
|
||||
class ScoreNewsSerializer(serializers.ModelSerializer):
|
||||
user = serializers.CharField(source='author.username')
|
||||
@@ -23,7 +27,8 @@ class CommentNewsSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = CommentNews
|
||||
fields = '__all__'
|
||||
fields = '__all__'
|
||||
|
||||
def get_user(self, obj):
|
||||
return ShortUserSerializer(DictEmployee.objects.get(login=obj.author.username)).data
|
||||
|
||||
@@ -35,6 +40,7 @@ class NewsSerializer(serializers.ModelSerializer):
|
||||
author = serializers.SerializerMethodField('get_user')
|
||||
scores= serializers.SerializerMethodField('get_score')
|
||||
comment = serializers.SerializerMethodField('get_comment')
|
||||
gallery = serializers.SerializerMethodField('get_gallery')
|
||||
|
||||
class Meta:
|
||||
model = News
|
||||
@@ -51,6 +57,11 @@ class NewsSerializer(serializers.ModelSerializer):
|
||||
|
||||
def get_comment(self, obj):
|
||||
return CommentNewsSerializer(obj.get_comment_news.all(), many=True).data
|
||||
|
||||
def get_gallery(self, obj):
|
||||
# print(obj.get_gallery.all(), '---------------------')
|
||||
# return 'gal'
|
||||
return GallerySerializer(obj.get_gallery_news.all(), many=True).data
|
||||
|
||||
class CarouselsSerializer(serializers.ModelSerializer):
|
||||
|
||||
|
||||
Reference in new issue
Block a user