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
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
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)
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
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
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
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
def last_updated(cls): return db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, index=True)
def date_created(cls): return db.Column(db.DateTime, default=datetime.utcnow, index=True)