class MovieAdmin(BaseAdmin): """ Movie admin model """ roles_name = 'cast' list_display = ('id', 'year') + translated_fields('title') + ( 'roles_count', 'view', ) list_display_links = ('id', ) autocomplete_fields = ('sequel_for', 'prequel_for', 'remake_for') search_fields = translated_fields('title', with_base=True) form = MovieForm inlines = (CastInline, ) fieldsets = ( (None, { 'fields': ( ( 'title', 'year', ), translated_fields('title'), ('runtime', 'novel_isbn'), ), }), (_('Associations with other movies'), { 'classes': ('collapse', 'collapsed'), 'fields': ('sequel_for', 'prequel_for', 'remake_for'), }), (_('Genres, languages and countries'), { 'classes': ('collapse', 'collapsed'), 'fields': ('genres', 'languages', 'countries'), }), )
class PersonAdmin(BaseAdmin): """ Person admin model """ roles_name = 'career' list_display = ('id', ) + translated_fields('first_name', 'last_name') + ( 'date_birth', 'date_death', 'roles_count', 'view') list_display_links = ('id', ) search_fields = translated_fields('first_name', 'last_name', with_base=True) inlines = (CastInline, ) fieldsets = ((None, { 'fields': ( ('first_name', 'last_name', 'gender'), translated_fields('first_name', 'last_name'), ('country', 'date_birth', 'date_death'), ) }), )
class Meta: model = Movie only_fields = translated_fields('title') + ( 'id', 'title_original', 'year', 'runtime', 'award', 'genres', 'countries', 'languages', 'sequel_for', 'prequel_for', 'remake_for', 'imdb', 'kinopoisk', ) interfaces = (relay.Node,) connection_class = CountableConnectionBase
class SitesMovieAdmin(SitesAdminMixin, MovieAdmin): # type: ignore list_display = MovieAdmin.list_display + ('imdb_id', 'imdb_rating', 'kinopoisk_id', 'kinopoisk_rating') + \ translated_fields('wikipedia') list_select_related = ('imdb', 'kinopoisk') list_filter = (ImdbFilter, KinopoiskFilter) + wikipedia_filters inlines = (ImdbMovieInline, KinopoiskMovieInline, WikipediaPageInline) + MovieAdmin.inlines def imdb_rating(self, obj): return obj.imdb.rating def kinopoisk_rating(self, obj): return obj.kinopoisk.rating
class Meta: model = Person only_fields = translated_fields('first_name', 'last_name') + ( 'id', 'gender', 'date_birth', 'date_death', 'country', 'roles', 'imdb', 'kinopoisk', ) interfaces = (relay.Node, ) connection_class = CountableConnectionBase
class Meta: model = Movie fields = translated_fields('title', with_base=True) + ( 'year', 'runtime', 'novel_isbn', 'sequel_for', 'prequel_for', 'remake_for', 'novel_isbn', 'genres', 'languages', 'countries', 'site_official_url', 'site_fan_url', )
def test_translated_fields_with_base(self): self.assertEqual(translated_fields('field', with_base=True), ['field', 'field_en', 'field_ru'])
def test_translated_fields_one(self): self.assertEqual(translated_fields('field'), ['field_en', 'field_ru'])
def test_translated_fields_multiple(self): self.assertEqual(translated_fields('field1', 'field2'), ['field1_en', 'field2_en', 'field1_ru', 'field2_ru'])
class SitesPersonAdmin(SitesAdminMixin, PersonAdmin): # type: ignore list_display = PersonAdmin.list_display + ('imdb_id', 'kinopoisk_id') + translated_fields('wikipedia') list_select_related = ('imdb', 'kinopoisk') list_filter = (ImdbFilter, KinopoiskFilter) + wikipedia_filters inlines = (ImdbPersonInline, KinopoiskPersonInline, WikipediaPageInline) + PersonAdmin.inlines
import graphene from graphene_django import DjangoObjectType from cinemanio.api.helpers import global_id from cinemanio.api.utils import DjangoObjectTypeMixin from cinemanio.core.models import Genre, Language, Country, Role from cinemanio.core.utils.languages import translated_fields PROPERTY_FIELDS = ('id', ) + translated_fields('name') class RoleNode(DjangoObjectTypeMixin, DjangoObjectType): class Meta: model = Role only_fields = PROPERTY_FIELDS def resolve_id(self, info): return global_id(Role(id=self.pk)) class GenreNode(DjangoObjectType): class Meta: model = Genre only_fields = PROPERTY_FIELDS def resolve_id(self, info): return global_id(Genre(id=self.pk)) class LanguageNode(DjangoObjectType): class Meta:
from typing import Tuple from django.contrib.admin import register from reversion.admin import VersionAdmin from cinemanio.core.admin.site import site from cinemanio.core.models import Genre, Country, Language from cinemanio.core.utils.languages import translated_fields Param = Tuple[str, ...] names = translated_fields('name', with_base=True) class PropAdminBase(VersionAdmin): """Base admin model for props""" list_display: Param = ('id',) + names + ('imdb_name', 'kinopoisk_name') list_display_links: Param = ('id',) list_editable: Param = names ordering: Param = ('id',) def imdb_name(self, obj): return obj.imdb.name imdb_name.admin_order_field = 'imdb__name' # type: ignore def kinopoisk_name(self, obj): return obj.kinopoisk.name kinopoisk_name.admin_order_field = 'kinopoisk__name' # type: ignore