Пример #1
0
class Tag(db.Model):
    id = database.PrimaryKeyField()
    name = database.CharField(100)

    posts = database.ManyToManyField(rel='post_tag_re', to_table='post')

    def __repr__(self):
        return '<Tag %s>' % self.name
Пример #2
0
class Author(db.Model):
    id = database.PrimaryKeyField()
    name = database.CharField(100)

    posts = database.ForeignKeyReverseField('self_define_post')

    def __repr__(self):
        return '<Author %s>' % self.name
Пример #3
0
class Post_Tag_Re(db.Model):
    id = database.PrimaryKeyField()
    post_id = database.ForeignKeyField('post')
    tag_id = database.ForeignKeyField('tag')

    def __repr__(self):
        return '<Relation table post_id = %s, tag_id = %s>' %(
            self.post_id, self.tag_id
            )
Пример #4
0
class Comment(db.Model):
    id = database.PrimaryKeyField()
    title = database.CharField(100)
    content = database.CharField(400)
    pub_date = database.DateField()

    post_id = database.ForeignKeyField('post')

    def __repr__(self):
        return '<Comment %s>' % self.title
Пример #5
0
class Post_Tag_Re(db.Model):
    """
    Many to many relationship test.
    """
    id = database.PrimaryKeyField()
    post_id = database.ForeignKeyField('self_define_post')
    tag_id = database.ForeignKeyField('tag')

    def __repr__(self):
        return '<Relation table post_id = %s, tag_id = %s>' % (self.post_id,
                                                               self.tag_id)
Пример #6
0
class Post(db.Model):
    __tablename__ = 'post'

    id = database.PrimaryKeyField()
    title = database.CharField(100)
    content = database.TextField()
    pub_date = database.DateField()

    tags = database.ManyToManyField(rel='post_tag_re', to_table='tag')
    comments = database.ForeignKeyReverseField('comment')

    def __repr__(self):
        return '<Post %s>' % self.title