flask_tut.models.Address.__repr__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 1
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