Beispiel #1
0
class Timezone(AppMixin, db.Model):
    code = db.Column(db.String(200),
                     primary_key=True,
                     nullable=False,
                     index=True,
                     unique=True)
    name = db.Column(db.String(200))
    offset = db.Column(db.String(200))  # UTC time

    def __unicode__(self):
        return self.name

    def __repr__(self):
        return '<Timezone %r>' % self.name
Beispiel #2
0
class Currency(AppMixin, db.Model):
    code = db.Column(db.String(200),
                     nullable=False,
                     index=True,
                     primary_key=True)
    name = db.Column(db.String(200))
    enabled = db.Column(db.Boolean, default=False)
    symbol = db.Column(db.String(200))
    payment_code = db.Column(db.String(200))

    def __unicode__(self):
        return "%s (%s)" % (self.name.title(), self.code)

    def __repr__(self):
        return '<Currency %r>' % self.name
Beispiel #3
0
class Street(AppMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(200))
    code = db.Column(db.String(200))

    city_id = db.Column(db.Integer, db.ForeignKey('city.id'), nullable=False)
    city = db.relationship('City', foreign_keys="Street.city_id")

    district_id = db.Column(db.Integer,
                            db.ForeignKey('district.id'),
                            nullable=True)
    district = db.relationship('District', foreign_keys="Street.district_id")

    state_code = db.Column(db.String(200),
                           db.ForeignKey('state.code'),
                           nullable=False)
    state = db.relationship('State', foreign_keys="Street.state_code")

    country_code = db.Column(db.String(200),
                             db.ForeignKey('country.code'),
                             nullable=False)
    country = db.relationship('Country', foreign_keys="Street.country_code")

    def __unicode__(self):
        return str(self.name)

    def __repr__(self):
        return str(self.name)
Beispiel #4
0
class District(AppMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200))
    code = db.Column(db.String(200))
    slug = db.Column(db.String(200), nullable=False, default=slugify_from_name)

    state_code = db.Column(db.String(200),
                           db.ForeignKey('state.code'),
                           nullable=False)
    state = db.relationship('State', foreign_keys="District.state_code")

    country_code = db.Column(db.String(200),
                             db.ForeignKey('country.code'),
                             nullable=False)
    country = db.relationship('Country', foreign_keys="District.country_code")

    city_id = db.Column(db.Integer,
                        db.ForeignKey('city.id', ondelete="SET NULL"),
                        nullable=False)
    city = db.relationship('City', foreign_keys="District.city_id")

    def __unicode__(self):
        return self.name

    def __repr__(self):
        return '<State %r>' % self.name
Beispiel #5
0
class State(AppMixin, db.Model):
    code = db.Column(db.String(200),
                     nullable=False,
                     index=True,
                     unique=True,
                     primary_key=True)
    name = db.Column(db.String(200), index=True)
    slug = db.Column(db.String(200), nullable=False, default=slugify_from_name)

    country_code = db.Column(db.String(200),
                             db.ForeignKey('country.code'),
                             nullable=False)

    country = db.relationship("Country", foreign_keys="State.country_code")

    def __unicode__(self):
        return self.name

    def __repr__(self):
        return '<State %r>' % self.name
Beispiel #6
0
class Country(AppMixin, db.Model):
    code = db.Column(db.String(200),
                     nullable=False,
                     index=True,
                     unique=True,
                     primary_key=True)
    name = db.Column(db.String(200), nullable=False, index=True, unique=True)
    slug = db.Column(db.String(200), nullable=False, default=slugify_from_name)
    phone_code = db.Column(db.String)
    enabled = db.Column(db.Boolean, default=False)
    requires_post_code = db.Column(db.Boolean, default=False)

    timezone_code = db.Column(db.String(200),
                              db.ForeignKey('timezone.code'),
                              nullable=True)
    timezone = db.relationship("Timezone",
                               foreign_keys="Country.timezone_code")

    def __unicode__(self):
        return self.name

    def __repr__(self):
        return '<Country %r>' % self.name
Beispiel #7
0
class City(AppMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200))
    zipcode = db.Column(db.String(200))
    slug = db.Column(db.String(200), nullable=False, default=slugify_from_name)
    state_code = db.Column(db.String(200),
                           db.ForeignKey('state.code'),
                           nullable=False)
    state = db.relationship("State", foreign_keys="City.state_code")

    country_code = db.Column(db.String(200),
                             db.ForeignKey('country.code'),
                             nullable=False)
    country = db.relationship("Country", foreign_keys="City.country_code")

    # __table_args__ = (
    #     UniqueConstraint("slug", "state_code", "country_code"),
    # )

    def __unicode__(self):
        return self.name

    def __repr__(self):
        return '<State %r>' % self.name
Beispiel #8
0
 def last_updated(cls):
     return db.Column(db.DateTime,
                      default=datetime.utcnow,
                      onupdate=datetime.utcnow,
                      index=True)
Beispiel #9
0
 def date_created(cls):
     return db.Column(db.DateTime, default=datetime.utcnow, index=True)