Coverage for bundesliga_tippspiel/db/user_generated/UserProfile.py: 94%

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

15 statements  

1"""LICENSE 

2Copyright 2017 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of bundesliga-tippspiel. 

5 

6bundesliga-tippspiel 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. 

10 

11bundesliga-tippspiel 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. 

15 

16You should have received a copy of the GNU General Public License 

17along with bundesliga-tippspiel. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19from typing import Optional 

20 

21from jerrycan.base import db 

22from jerrycan.db.ModelMixin import ModelMixin 

23from jerrycan.db.User import User 

24from bundesliga_tippspiel.db import Team 

25 

26 

27class UserProfile(ModelMixin, db.Model): 

28 """ 

29 Model that describes the 'user_profiles' SQL table 

30 """ 

31 

32 def __init__(self, *args, **kwargs): 

33 """ 

34 Initializes the Model 

35 :param args: The constructor arguments 

36 :param kwargs: The constructor keyword arguments 

37 """ 

38 super().__init__(*args, **kwargs) 

39 

40 __tablename__ = "user_profiles" 

41 

42 user_id: int = db.Column( 

43 db.Integer, 

44 db.ForeignKey("users.id", ondelete="CASCADE"), 

45 primary_key=True 

46 ) 

47 favourite_team_abbreviation: Optional[str] = db.Column( 

48 db.String(3), 

49 db.ForeignKey("teams.abbreviation"), 

50 nullable=True 

51 ) 

52 description: Optional[str] = db.Column(db.String(255), nullable=True) 

53 country: Optional[str] = db.Column(db.String(255), nullable=True) 

54 

55 user: User = db.relationship( 

56 "User", 

57 backref=db.backref("profile", cascade="all, delete", uselist=False), 

58 ) 

59 favourite_team: Team = db.relationship("Team")