Exemplo n.º 1
0
def test_database():
    test_db = SqliteExtDatabase(":memory:")
    with test_db.bind_ctx(ALL_MODELS):
        test_db.create_tables(ALL_MODELS)
        try:
            yield
        finally:
            test_db.drop_tables(ALL_MODELS)
            test_db.close()
Exemplo n.º 2
0
def database():
    db = SqliteExtDatabase(':memory:')
    create_tables(db)
    yield db
    db.drop_tables([Ability, Character])
Exemplo n.º 3
0
    name = peewee.CharField()
    students = ManyToManyField(Student, related_name='groups')


StudentGroup = Group.students.get_through_model()


class Discipline(BaseModel):
    name = peewee.CharField(unique=True)


class Task(BaseModel):
    name = peewee.CharField()
    maxRate = peewee.IntegerField()
    rateWeight = peewee.IntegerField()
    discipline = peewee.ForeignKeyField(Discipline, related_name='tasks')
    date = peewee.DateTimeField()


class Mark(BaseModel):
    task = peewee.ForeignKeyField(Task, related_name='marks')
    student = peewee.ForeignKeyField(Student, related_name='marks')
    rate1 = peewee.FloatField()
    rate2 = peewee.FloatField(null=True)
    date = peewee.DateTimeField()


db.drop_tables([Student, Group, StudentGroup, Discipline, Task, Mark],
               safe=True)
db.create_tables([Student, Group, StudentGroup, Discipline, Task, Mark])
Exemplo n.º 4
0
from peewee import *
from playhouse.sqlite_ext import SqliteExtDatabase
from models.student import Student
from models.course import Course
from models.group import Group
from models.registry import Registry
from models.score import Score

db = SqliteExtDatabase("data.db")
"""
    Recreate the tables
"""

db.connect()
db.drop_tables([Student, Course, Group, Registry, Score])
db.create_tables([Student, Course, Group, Registry, Score])
"""
    Populate database
"""

mia = Student.create(name="Mía",
                     lastname="Figueroa",
                     gender="F",
                     dni="50348343",
                     address="Jr. Cuzco #756",
                     phone="946485322",
                     email="*****@*****.**")
danna = Student.create(name="Danna",
                       lastname="Valenzuela",
                       gender="F",
                       dni="49357820",