Coverage for otaku_info/db/MediaListItem.py: 95%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of otaku-info.
6otaku-info is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11otaku-info is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with otaku-info. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from jerrycan.base import db
21from jerrycan.db.ModelMixin import ModelMixin
22from otaku_info.db.MediaList import MediaList
23from otaku_info.db.MediaUserState import MediaUserState
24from otaku_info.enums import ListService, MediaType
27class MediaListItem(ModelMixin, db.Model):
28 """
29 Database model for media list items.
30 This model maps MediaLists and MediaUserStates
31 """
33 def __init__(self, *args, **kwargs):
34 """
35 Initializes the Model
36 :param args: The constructor arguments
37 :param kwargs: The constructor keyword arguments
38 """
39 super().__init__(*args, **kwargs)
41 __tablename__ = "media_list_items"
42 __table_args__ = (
43 db.ForeignKeyConstraint(
44 ("user_state_service", "user_state_service_id",
45 "user_state_media_type", "user_state_user_id"),
46 (MediaUserState.service, MediaUserState.service_id,
47 MediaUserState.media_type, MediaUserState.user_id)
48 ),
49 db.ForeignKeyConstraint(
50 ("media_list_service", "media_list_media_type",
51 "media_list_user_id", "media_list_name"),
52 (MediaList.service, MediaList.media_type,
53 MediaList.user_id, MediaList.name)
54 )
55 )
57 user_state_service: ListService =\
58 db.Column(db.Enum(ListService), primary_key=True)
59 user_state_service_id: str = db.Column(db.String(255), primary_key=True)
60 user_state_media_type: MediaType = \
61 db.Column(db.Enum(MediaType), primary_key=True)
62 user_state_user_id: int = db.Column(db.Integer, primary_key=True)
64 media_list_service: ListService = \
65 db.Column(db.Enum(ListService), primary_key=True)
66 media_list_media_type: MediaType = \
67 db.Column(db.Enum(MediaType), primary_key=True)
68 media_list_user_id: int = db.Column(db.Integer, primary_key=True)
69 media_list_name: int = db.Column(db.String(255), primary_key=True)
71 user_state: MediaUserState = db.relationship(
72 "MediaUserState", back_populates="media_list_items"
73 )
74 media_list: MediaList = db.relationship(
75 "MediaList", back_populates="list_items"
76 )