Beispiel #1
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    firstq = db.Column(db.Text, nullable=False)
    secondq = db.Column(db.Text, nullable=False)
    thirdq = db.Column(db.Text, nullable=False)
    forthq = db.Column(db.Text, nullable=False)
    fifthq = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
Beispiel #2
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    content = db.Column(db.Text, nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    like_count = db.Column(db.Integer, nullable=False, default=0)
    category_id = db.Column(db.Integer,
                            db.ForeignKey('category.id'),
                            nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    comments = db.relationship('Comment', backref='comment', lazy=True)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
class FoodDB(db.Model):  #from food API
    __tablename__ = 'FoodDB'
    food_id = db.Column(db.Integer, primary_key=True)
    food_name = db.Column(db.String(50), nullable=False)
    food_calories = db.Column(db.Float, nullable=False)
    food_protein = db.Column(db.Float, nullable=False)
    food_carb = db.Column(db.Float, nullable=False)
    food_fat = db.Column(db.Float, nullable=False)
    food_fibres = db.Column(db.Float, nullable=False)
    food_saturatedfat = db.Column(db.Float, nullable=False)
    food_sodium = db.Column(db.Float, nullable=False)
    serving_size = db.Column(db.Float, nullable=False)
    Food = db.relationship("Food",
                           backref="FoodDB",
                           cascade="all, delete, delete-orphan",
                           passive_deletes=True)
class FoodRecord(db.Model):  #a food record that user eat
    __tablename__ = 'FoodRecord'
    foodrecord_id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('User.user_id', ondelete='CASCADE'),
                        nullable=False)
    foodrecord_date = db.Column(db.DateTime,
                                nullable=False,
                                default=datetime.now())
    foodrecord_meal = db.Column(db.String(20),
                                nullable=False,
                                default='Breakfast')
    Food = db.relationship("Food",
                           backref="FoodRecord",
                           cascade="all, delete, delete-orphan",
                           passive_deletes=True)
Beispiel #5
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.DateTime, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    @hybrid_property
    def expiry(self):
        today = datetime.today()
        return self.content - today

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
Beispiel #6
0
class Post(db.Model):
    __table_name = 'post'
    __table_args__ = {'schema': 'rosarsa_crm'}
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    #user = db.relationship('User', backref='user')
    user_id = db.Column(db.Integer,
                        db.ForeignKey('rosarsa_crm.user.id'),
                        nullable=False)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
Beispiel #7
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    published = db.Column(db.Boolean, default=False)
    comments = db.relationship('Comment', backref='post_comments', lazy=True)
    user_tag = db.Column(db.Text)
    likes = db.relationship('PostLike', backref='post', lazy='dynamic')
    theme = db.Column(db.Integer, default=1)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}', '{self.published}', '{self.user_tag}', '{self.theme}')"
Beispiel #8
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    #def __init__(self,title,content,date_posted):
    #    self.title=title
    #    self.content=content
    #    self.date_posted=date_posted

    def __repr__(self):
        return f"Post('{self.title}','{self.content}','{self.date_posted}')"
Beispiel #9
0
class Blog(db.Model):
    blog_id = db.Column(db.Integer, primary_key=True)
    subject = db.Column(db.String(100), nullable=False)
    date_blogged = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    description = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    # Blog can have many comments
    comment = db.relationship('Comment', backref='blog', lazy=True)
    # Blog can have many tags
    tag = db.relationship('Tag', backref='blog', lazy=True)

    def __repr__(self):
        return f"Post('{self.subject}', '{self.date_blogged}')"
Beispiel #10
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow())
    content = db.Column(
        db.Text,
        nullable=False,
    )
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    #this is how our object is printed whenever we print it out
    def __repr__(self):
        #print Post Object, "f" is for concatenate
        return f"Post('{self.title}', '{self.date_posted}')"
Beispiel #11
0
class Post(db.Model):
    '''
    - modelul de postare
    - contine campurile de completare a unei 
        postari
    '''
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
Beispiel #12
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)

    # we are passing utcnow as an argument and not as a function
    # utcnow() because we don't want to pass the
    # current date as an argument. The function will run after it's passed along
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)

    # Linking Post table to User table using FK user.id. Since we are referencing the User table
    # we are using lowercase "user"
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Post('{self.title}' , '{self.date_posted}')"
Beispiel #13
0
class DeletedPost(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime, nullable=False)
    date_edited = db.Column(db.DateTime, nullable=False)
    date_deleted = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    post_history = db.relationship('DeletedPostHistory',
                                   backref='post',
                                   lazy=True)

    def __repr__(self):
        return f"User('{self.title}', '{self.date_posted}')"
Beispiel #14
0
class Post(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    location = db.Column(Geometry("POINT", srid=4326, dimension=2, management=True))
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    type_of_service = db.Column(db.Integer, nullable=False)
    category = db.Column(db.Integer, nullable=False)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def get_service_location_lat(self):
        point = to_shape(self.location)
        return point.x

    def get_service_location_lng(self):
        point = to_shape(self.location)
        return point.y

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}', '{self.location}', '{self.content}')"

    @staticmethod
    def point_representation(lat, lng):
        point = "POINT(%s %s)" % (lat, lng)
        wkb_element = WKTElement(point, srid=4326)
        return wkb_element

    def to_dict(self):
        return {
            "id": self.id,
            "username": self.profile.user.username,
            "title": self.title,
            "location": {
                "lat": self.get_service_location_lat(),
                "lng": self.get_service_location_lng(),
            },
            "content": self.content,
            "service": self.service,
        }

    @staticmethod
    def get_services_within_radius(lat, lng, radius):
        """Return all service posts within a given radius (in meters)"""
        return Post.query.filter(
            func.PtDistWithin(Post.location, func.MakePoint(lat, lng, 4326), radius)
        ).all()
Beispiel #15
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String(20), nullable=False)
    lastname = db.Column(db.String(20), nullable=False)
    phone = db.Column(db.String(20), unique=True, nullable=False)
    roll = db.Column(db.String(20), unique=True, nullable=False)
    rank = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)

    #role = db.Column(db.Integer, nullable=False, default=1)

    def __repr__(self):
        return f"User('{self.id}','{self.firstname}','{self.lastname}', '{self.email}', '{self.image_file}')"
Beispiel #16
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(80), nullable=True)
    last_name = db.Column(db.String(80), nullable=True)
    gender = db.Column(db.String(20), nullable=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    post = db.relationship('Post', backref='user', lazy='dynamic')
    roles = db.relationship('Role', secondary='user_roles', backref='usrroles')
Beispiel #17
0
class Post(db.Model):
    # (1)设置table相关属性
    # __tablename__ = "Post"                                                    # 用于设置table的名字,table表名默认为类名Post
    id = db.Column(db.Integer, primary_key=True)  # 定义为primary_key的属性会自动生成编号
    title = db.Column(db.String(100), nullable=False)
    post_date = db.Column(
        db.DateTime, nullable=False,
        default=datetime.now)  # 使用datetime模块中的datetime.utcnow方法获取当前时间
    # 我们在alexnet模型代码中,写了:now_str = dt.datetime.now().strftime("%Y-%m-%d_%H%M%S")  使用datetime模块里的datetime.now()方法取得当前时间,并格式化 #
    content = db.Column(db.Text, nullable=False)

    # 【这里的user_id需要理解!】  db.ForeignKey的用法需要学习!!!!!!!
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)

    # (2)定义了直接print(Post类对象)的输出内容
    def __repr__(self):
        return f"博文信息< 文章标题:{self.title}, 发布时间:{self.post_date} >"
Beispiel #18
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    # ForeignKey에 들어가는 attiribute가 소문자로 user임에 주의.
    # In the user model, we are referencing the actual post class, and in the foreign key we are actually referecing the table and the column name.
    # So it's a lower case. So the user model automatically has this table name set to lower case 'user', and the post model will have a table name
    # automatically set to lower case 'post'. If you want to set your own table names, then you can set a specific table name atttribute.
    # but since our models are pretty simple, we'll just leave those as the default lower case value.

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
Beispiel #19
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(20), nullable=False)

    def posttime(self):
        dt = str(datetime.now().date())
        t = str(datetime.now().time().hour) + ':' + str(
            datetime.now().time().minute)
        return "Date - " + dt + " | Time - " + t + " Hrs"

    # print(posttime())
    date_posted = db.Column(db.String, nullable=False, default=posttime)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
class ExerciseDB(db.Model):  # from exercise API
    __tablename__ = 'ExerciseDB'
    exercise_id = db.Column(db.Integer, primary_key=True)
    exercise_desc = db.Column(db.String(1000000), nullable=False)
    exercise_caloriesburnt = db.Column(db.Float, nullable=False)
    Exercise = db.relationship("Exercise",
                               backref="ExerciseDB",
                               cascade="all, delete",
                               passive_deletes=True)
    Set = db.relationship("Set",
                          backref="ExerciseDB",
                          cascade="all, delete, delete-orphan",
                          passive_deletes=True)
    Rep = db.relationship("Rep",
                          backref="ExerciseDB",
                          cascade="all, delete, delete-orphan",
                          passive_deletes=True)
Beispiel #21
0
class Post(db.Model):
    __tablename__ = 'post'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)

    # the User and Post model will have a one to many relationship,
    # because one user can have multiple posts, but a post can only have 1 author,
    # i.e. Post will be the child table
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return "Post('{}', '{}')".format(self.title, self.date_posted)
Beispiel #22
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(
        db.DateTime, nullable=False, default=datetime.utcnow
    )  #default is taken beacuse if no date is specified then it will take the current time so we take datetime module
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"  #this will be printed out as Post

        #we are not adding authors to post model because post model and user model will have a relationship, users will author post.
        #This is a one to many relationship, bcz one user can have multiple post but a post can ave only one author


#Now by these 2 above database models we will create database by using command line
Beispiel #23
0
class Post(db.Model):
    __tablename__ = 'post'
    __searchable__ = ['date_posted', 'tags']
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    tags = db.relationship('Tag',
                           secondary=tags,
                           lazy='subquery',
                           backref=db.backref('pages', lazy=True))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}', {self.tags})"
Beispiel #24
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    keywords = db.Column(db.Text, nullable=False)
    url = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    reviews = db.relationship('Review', backref='origin', lazy=True)
    graphs = db.relationship('Graph',
                             backref='gg',
                             lazy=True,
                             cascade="save-update, merge, delete")

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
Beispiel #25
0
class Event(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.Date, nullable=False)
    time = db.Column(db.Time, nullable=False)
    cost = db.Column(db.Float, nullable=False, default='To be defined')
    np = db.Column(db.Integer, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    club_id = db.Column(db.Integer, db.ForeignKey('club.id'), nullable=False)
    sport_id = db.Column(db.Integer, db.ForeignKey('sport.id'), nullable=False)
    level = db.Column(db.String(60))
    participant2 = db.relationship('Participant',
                                   foreign_keys=[Participant.e_id],
                                   backref='part',
                                   lazy=True)

    def __repr__(self):
        return '<Event %r %r %r>' % self.date % self.time % self.np
Beispiel #26
0
class Competancy_rec(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement="auto")
    mark = db.Column(db.Boolean, nullable=True)
    comp_id = db.Column(db.String,
                        db.ForeignKey('comp.descrip'),
                        nullable=False)
    comp_name = db.Column(db.String(100), nullable=False)
    clinician_id = db.Column(db.Integer,
                             db.ForeignKey('user2.id'),
                             nullable=False)
    student_id = db.Column(db.Integer,
                           db.ForeignKey('student.id'),
                           nullable=False)
    timestamp = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

    def __repr__(self):
        return f"Comp_rec('{self.id}', '{self.mark}', '{self.comp_id}', '{self.clinician_id}', '{self.student_id}', '{self.timestamp}')"
Beispiel #27
0
class Notification(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    notification_type = db.Column(db.String(30), nullable=False)
    has_been_read = db.Column(db.Boolean, nullable=False, default=False)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'), nullable=True)
    posts = db.relationship(Post, backref='notification', lazy=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    users = db.relationship(User, backref='notification', lazy=True)
    comment_id = db.Column(db.Integer,
                           db.ForeignKey('comment.id'),
                           nullable=True)
    comments = db.relationship(Comment, backref='notification', lazy=True)
    reply_id = db.Column(db.Integer, db.ForeignKey('reply.id'), nullable=True)
    replies = db.relationship(Reply, backref='notification', lazy=True)
Beispiel #28
0
class Course(db.Model):
    course_name = db.Column(db.String(100), primary_key=True)
    level = db.Column(db.String(100))
    level_slug = db.Column(db.String(100))
    age = db.Column(db.Integer)
    duration = db.Column(db.String(100))
    slug = db.Column(db.String(100))
    price_e_learning = db.Column(db.Integer)
    price_book_learning = db.Column(db.Integer)
    pool_dives = db.Column(db.Integer)
    ocean_dives = db.Column(db.Integer)
    min_dives = db.Column(db.String(100))
    qualified_to = db.Column(db.String(255))
    basic_info = db.Column(db.Text)
    schedule = db.Column(db.Text)
    image = db.Column(db.String(100), default='default_course.jpg')

    def __repr__(self):
        return f"Site('{self.course_name}', '{self.level}')"
Beispiel #29
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    Username = db.Column(db.String(50), nullable=False)
    Address = db.Column(db.String(100), nullable=True)
    PhoneNumber = db.Column(db.String(13), unique=True, nullable=False)
    PlotNumber = db.Column(db.String(10), unique=True, nullable=False)
    FlatNumber = db.Column(db.String(10), nullable=True)
    PaymentStatus = db.Column(db.String(10), nullable=False, default="False")
    Role = db.Column(db.String(10), nullable=False, default="User")
    Date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.today())
    payment = db.relationship('Payment', backref='author', lazy=True)

    def __repr__(self):
        return f"User('{self.Username}', '{self.PhoneNumber}', '{self.PlotNumber}','{self.PaymentStatus}','{self.Role}','{self.Date_created}')"
Beispiel #30
0
class Posts(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    # referecing table/column name (lower case user name)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    # how object is printed
    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"

    def __init__(self, title, content, user_id):
        self.title = title
        self.content = content
        self.user_id = user_id