class Movie(models.Model):
title = models.CharField('Название', max_length=100)
tagline = models.CharField('Слоган', max_length=100, default='')
descriptions = models.TextField('Описание')
poster = models.ImageField('Постер', upload_to='movies/')
year = models.PositiveSmallIntegerField('Дата выхода', default=2019)
country = models.CharField('Страна', max_length=30)
directors = models.ManyToManyField(Actor, verbose_name='Режиссёр', related_name='film_director')
actors = models.ManyToManyField(Actor, verbose_name='Актёры', related_name='film_actor')
genres = models.ManyToManyField(Genre, verbose_name='Жанры')
world_premiere = models.DateField('Примьера в мире', default=date.today)
budget = models.PositiveIntegerField('Бюджет', default=0, help_text='Цену указывать в доларах')
fees_in_usa = models.PositiveIntegerField('Сборы в США', default=0, help_text='Цену указывать в доларах')
fees_in_world = models.PositiveIntegerField('Сборы в Мире', default=0, help_text='Цену указывать в доларах')
category = models.ForeignKey(Category, verbose_name='Категория', on_delete=models.SET_NULL, null=True)
url = models.SlugField(max_length=130, unique=True)
draft = models.BooleanField('Черновик', default=False)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('movie_detail', kwargs={'slug': self.url})
def get_review(self):
return self.reviews_set.filter(parent__isnull=True)
class Meta:
verbose_name = 'Фильм'
verbose_name_plural = 'Фильмы'
@admin.register(Movie)
class MovieAdmin(admin.ModelAdmin):
"""Фильм"""
list_display = ('title', 'category', 'url', 'draft')
list_filter = ('category', 'year')
search_fields = ('title', 'category__name')
inlines = [MovieShotsInLine, ReviewInLine]
save_on_top = True
save_as = True
list_editable = ('draft',)
readonly_fields = ('get_image',)
fieldsets = (
(None, {
"fields": (("title", "tagline"),)
}),
(None, {
"fields": ("descriptions", ("poster", 'get_image'))
}),
(None, {
"fields": (("year", "world_premiere", "country"),)
}),
("Actors", {
"classes": ("collapse",),
"fields": (("actors", "directors", "genres", "category"),)
}),
(None, {
"fields": (("budget", "fees_in_usa", "fees_in_world"),)
}),
("Options", {
"fields": (("url", "draft"),)
}),
)
def get_image(self, obj):
if obj.poster:
return mark_safe(f'
else:
return 'нет фото'
get_image.short_description = 'Постер'