from . import db


class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(55), unique=True, index=True)
    weather_station = db.relationship('Weather_Station', backref='meteorologist',
                                      lazy='dynamic')

    def __repr__(self):
        return '<User %s>' % self.name

    @staticmethod
    def insert_users(users=5):
        from sqlalchemy.exc import InternalError
        import forgery_py

        for user in range(users):
            data = User(name=forgery_py.name.first_name())

            db.session.add(data)
            try:
                db.session.commit()
            except InternalError:
                db.session.rollback()


class Weather_Station(db.Model):
    __tablename__ = 'stations'
    id = db.Column(db.Integer, primary_key=True)
    description = db.Column(db.String(255), unique=True)
    latitude = db.Column(db.String(255))
    longitude = db.Column(db.String(255))
    users = db.Column(db.Integer, db.ForeignKey('users.id'))

    def __repr__(self):
        return '<Weather_Station %s>' % self.description

    @staticmethod
    def insert_stations(stations=5):
        from sqlalchemy.exc import InternalError
        import forgery_py

        for station in range(stations):
            data = Weather_Station(description=forgery_py.address.street_name(),
                                   latitude=str(forgery_py.geo.latitude_degrees()) +
                                   str(forgery_py.geo.latitude_direction()),
                                   longitude=str(forgery_py.geo.longitude_degrees()) +
                                   str(forgery_py.geo.longitude_direction()))

            db.session.add(data)
            try:
                db.session.commit()
            except InternalError:
                db.session.rollback()

@@ -12,16 +12,218 @@
 rt db%0A%0A%0A
+association_table = db.Table('association', db.Model.metadata,%0A    db.Column('user_id', db.Integer, db.ForeignKey('users.id')),%0A    db.Column('station_id', db.Integer, db.ForeignKey('stations.id'))%0A)%0A%0A%0A
 class Us
@@ -377,144 +377,8 @@
 rue)
-%0A    weather_station = db.relationship('Weather_Station', backref='meteorologist',%0A                                      lazy='dynamic')
 %0A%0A  
@@ -1090,52 +1090,84 @@
  db.
-Column(db.Integer, db.ForeignKey('users.id')
+relationship(%22User%22,%0A                            secondary=association_table
 )%0A%0A 
@@ -1740,32 +1740,32 @@
 de_degrees()) +%0A
-
                 
@@ -1825,16 +1825,124 @@
 tion()))
+%0A            users = User.query.all()%0A            for user in users:%0A                data.users.append(user)
 %0A%0A      

Update models