hh
This commit is contained in:
1 parent
df5d962413
commit
fe115ae140
1132 files changed
+1671
-73
No files matched your search
@@ -0,0 +1,75 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from .models import *
|
||||
|
||||
class NewsAdmin(admin.ModelAdmin):
|
||||
list_display = ('title', 'author', 'text', 'cdate', 'link', 'get_html_photo')
|
||||
readonly_fields=('get_html_photo',)
|
||||
list_editable = ('link',)
|
||||
list_filter = ('cdate',)
|
||||
def save_model(self, request, obj, form, change):
|
||||
if (request.user.username != 'admin') :
|
||||
obj.author = request.user
|
||||
else :
|
||||
obj.author = User.objects.get(id=15)
|
||||
super().save_model(request, obj, form, change)
|
||||
|
||||
def get_html_photo(self, object):
|
||||
if object.link:
|
||||
return mark_safe(f"<img src='{object.link.url}' width=50>")
|
||||
|
||||
get_html_photo.short_description="Превью изображения"
|
||||
|
||||
class CarouselsAdmin(admin.ModelAdmin):
|
||||
list_display=('title', 'cdate', 'enddate', 'get_html_photo', 'link','published', 'sender')
|
||||
readonly_fields=('get_html_photo',)
|
||||
list_editable=('link','published', 'cdate', 'enddate', 'sender')
|
||||
list_filter=('cdate', 'enddate','published')
|
||||
fields=(('title', 'sender'), 'published', 'text', ('cdate', 'enddate'), ('link','get_html_photo'))
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
|
||||
if (request.user.username != 'admin') :
|
||||
obj.author = request.user
|
||||
else :
|
||||
obj.author = User.objects.get(id=15)
|
||||
super().save_model(request, obj, form, change)
|
||||
|
||||
def get_html_photo(self, object):
|
||||
if object.link:
|
||||
return mark_safe(f"<img src='{object.link.url}' width=50>")
|
||||
|
||||
get_html_photo.short_description="Изображение"
|
||||
|
||||
class BaseSenderAdmin(admin.ModelAdmin):
|
||||
list_display=('name', 'get_html_photo', 'img')
|
||||
list_editable=('img',)
|
||||
fields=('name', ('img', 'get_html_photo'))
|
||||
readonly_fields=('get_html_photo',)
|
||||
|
||||
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 ScoreNewsAdmin(admin.ModelAdmin):
|
||||
list_display = ('author', 'news', 'cdate', 'score')
|
||||
list_filter = ('author', 'cdate', 'score')
|
||||
|
||||
|
||||
class CommentNewsAdmin(admin.ModelAdmin):
|
||||
list_display = ('author', 'news', 'text', 'cdate')
|
||||
list_filter = ('author', 'cdate')
|
||||
|
||||
class LinksAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'link')
|
||||
list_display_links = ('link',)
|
||||
|
||||
admin.site.register(Links, LinksAdmin)
|
||||
admin.site.register(News, NewsAdmin)
|
||||
admin.site.register(Carousels, CarouselsAdmin)
|
||||
admin.site.register(BaseSender, BaseSenderAdmin)
|
||||
admin.site.register(ScoreNews, ScoreNewsAdmin)
|
||||
admin.site.register(CommentNews, CommentNewsAdmin)
|
||||
Reference in new issue
Block a user