from django.contrib import admin
from django import forms
from main_page.models import Page, Text, Audio, Video
# Register your models here.
class PageInline_Text(admin.StackedInline):
model = Text
extra = 0
class PageInline_Audio(admin.StackedInline):
model = Audio
extra = 0
class PageInline_Video(admin.StackedInline):
model = Video
extra = 0
class PageAdminForm(forms.ModelForm):
class Meta:
model = Page
fields = "__all__"
def clean(self):
values = list(self.data.values())
if not values[6] and not int(values[9]) and not int(values[16]):
msg = 'Не заполнено ни одно из полей (Текст, Аудио, Видео)'
self.add_error(None, msg)
class PageAdmin(admin.ModelAdmin):
form = PageAdminForm
fields = []
inlines = [PageInline_Text, PageInline_Audio, PageInline_Video]
admin.site.register(Page, PageAdmin)