lib.itmens/catalog/models.py

57 lines
1.4 KiB
Python
Raw Normal View History

2022-12-16 01:08:10 -05:00
from .common.models import Item
from .book.models import Edition, Work, Series
from .movie.models import Movie
from .tv.models import TVShow, TVSeason, TVEpisode
from .music.models import Album
from .game.models import Game
from .podcast.models import Podcast
from .performance.models import Performance
2022-12-12 16:46:37 +00:00
from .collection.models import Collection as CatalogCollection
2022-12-27 14:52:03 -05:00
from django.contrib.contenttypes.models import ContentType
# class Exhibition(Item):
# class Meta:
# proxy = True
# class Fanfic(Item):
# class Meta:
# proxy = True
# class Boardgame(Item):
# class Meta:
# proxy = True
2022-12-27 14:52:03 -05:00
2022-12-28 10:24:07 -05:00
_CATEGORY_LIST = None
_CONTENT_TYPE_LIST = None
def all_content_types():
global _CONTENT_TYPE_LIST
if _CONTENT_TYPE_LIST is None:
_CONTENT_TYPE_LIST = {}
for cls in Item.__subclasses__():
2022-12-29 23:57:02 -05:00
_CONTENT_TYPE_LIST[cls] = ContentType.objects.get(
app_label="catalog", model=cls.__name__.lower()
).id
2022-12-28 10:24:07 -05:00
return _CONTENT_TYPE_LIST
def all_categories():
global _CATEGORY_LIST
if _CATEGORY_LIST is None:
_CATEGORY_LIST = {}
for cls in Item.__subclasses__():
2022-12-29 23:57:02 -05:00
c = getattr(cls, "category", None)
2022-12-28 10:24:07 -05:00
if c not in _CATEGORY_LIST:
_CATEGORY_LIST[c] = [cls]
else:
_CATEGORY_LIST[c].append(cls)
return _CATEGORY_LIST