Total Complexity | 4 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import datetime |
||
2 | |||
3 | from flask_sqlalchemy import SQLAlchemy |
||
4 | |||
5 | db = SQLAlchemy() |
||
6 | |||
7 | |||
8 | class User(db.Model): |
||
9 | """Define a User.""" |
||
10 | |||
11 | __tablename__ = 'users' |
||
12 | |||
13 | id = db.Column(db.Integer, primary_key=True) |
||
14 | name = db.Column(db.Unicode, unique=True) |
||
15 | created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow) |
||
16 | address = db.relationship( |
||
17 | 'Address', uselist=False, backref=db.backref('user')) |
||
18 | |||
19 | def __unicode__(self): |
||
20 | """Give a readable representation of an instance.""" |
||
21 | return '{}'.format(self.name) |
||
22 | |||
23 | def __repr__(self): |
||
24 | """Give a unambiguous representation of an instance.""" |
||
25 | return '<{}#{}>'.format(self.__class__.__name__, self.id) |
||
26 | |||
27 | |||
28 | class Address(db.Model): |
||
29 | """Define an Address.""" |
||
30 | |||
31 | __tablename__ = 'addresses' |
||
32 | |||
33 | id = db.Column(db.Integer, primary_key=True) |
||
34 | description = db.Column(db.Unicode, unique=True) |
||
35 | user_id = db.Column(db.Integer, db.ForeignKey('users.id')) |
||
36 | |||
37 | def __unicode__(self): |
||
38 | """Give a readable representation of an instance.""" |
||
39 | return '{}'.format(self.id) |
||
40 | |||
41 | def __repr__(self): |
||
42 | """Give a unambiguous representation of an instance.""" |
||
43 | return '<{}#{}>'.format(self.__class__.__name__, self.id) |
||
44 |