예제 #1
0
class Inventory(Model):
    player: fields.OneToOneRelation[Player] = fields.OneToOneField(
        "models.Player",
        on_delete=fields.CASCADE,
        related_name="inventory",
        pk=True)

    education = fields.BigIntField(default=1)
    knowledge_points = fields.BigIntField(default=0)
    working_points = fields.BigIntField(default=0)
    research_points = fields.BigIntField(default=0)
    money = fields.BigIntField(default=0)  # Comes from work
    soap = fields.IntField(default=1)  # Can be bought
    food = fields.IntField(default=2)  # Can be bought
    airplane_ticket = fields.IntField(default=0)  # Can be bought
    lottery_ticket = fields.IntField(default=0)  # Can be bought
    herb = fields.IntField(default=0)  # Can be found
    music_cd = fields.IntField(default=0)  # Can be found
    pill = fields.IntField(default=0)  # Can be given to by doctors
    vaccine = fields.IntField(default=0)  # Can be given to by doctors
    mask = fields.IntField(default=0)  # Can be given to by doctors
    toilet_paper = fields.IntField(default=6)  # Can be used only
    gun = fields.IntField(default=0)  # Can be used only
    dagger = fields.IntField(default=1)  # Can be used only
    virus_test = fields.IntField(default=0)  # Can be given to by doctors
예제 #2
0
class VenueInformation(Model):
    name = fields.CharField(max_length=128)
    capacity = fields.IntegerField()
    rent = fields.FloatField()
    team = fields.OneToOneField("models.Team",
                                on_delete=fields.SET_NULL,
                                null=True)
예제 #3
0
class Profile(Model):
    id = fields.IntField(pk=True)
    user = fields.OneToOneField("app.User", related_name="profile")
    username = fields.CharField(16)
    bio = fields.CharField(256, null=True)
    image = fields.CharField(256, null=True)

    followings = fields.ManyToManyField("app.Profile", through="follow", related_name="followers")
    favorite_list = fields.ManyToManyField("app.Article", related_name="favorited", through="favorite")

    async def is_following(self, target):
        if self.id == target.id:
            return False
        return await self.followings.filter(id=target.id).exists()

    async def have_favorited(self, article) -> bool:
        return await self.favorite_list.filter(id=article.id).exists()

    async def favorite(self, article):
        await self.favorite_list.add(article)

    async def unfavorite(self, article):
        await self.favorite_list.remove(article)

    def __str__(self):
        return f"""Profile(id={self.id}, username={self.username})"""
예제 #4
0
class NmapScanTask(models.Model):
    id = fields.IntField(pk=True)

    name = fields.CharField(max_length=255)

    description = fields.TextField(null=True)

    options = fields.CharField(max_length=255)

    enabled = fields.BooleanField(default=True)

    created = fields.DatetimeField(null=True, auto_now_add=True)

    updated = fields.DatetimeField(null=True, auto_now=True)

    task: fields.OneToOneRelation[Task] = fields.OneToOneField(
        model_name='models.Task', related_name='nmap_scan_task')

    agent: fields.ForeignKeyRelation[RapidAgent] = fields.ForeignKeyField(
        model_name='models.RapidAgent', related_name='nmap_scan_task')

    targets: fields.ForeignKeyRelation[Target] = fields.ForeignKeyField(
        model_name='models.Target', related_name='nmap_scan_task')

    class Meta:
        table = 'scans_nmapscantask'
예제 #5
0
class User(Model):
    class Meta:
        table = 'users'

    id = fields.UUIDField(pk=True)
    auth_user: fields.OneToOneRelation[AuthUser] = fields.OneToOneField(
        'users.AuthUser',
        related_name='user',
        source_field='id_auth_user',
        to_field='id')
    first_name = fields.CharField(max_length=64, null=True)
    last_name = fields.CharField(max_length=64, null=True)
    email = fields.CharField(max_length=64, null=True)
    alarm_type = fields.IntField(default=0)
    notification_type = fields.IntField(default=0)
    phone = fields.CharField(max_length=64, null=True)
    data = fields.JSONField(null=True)
    language = fields.CharField(max_length=16, null=False, default=EN)

    async def get_display_name(self):

        if self.first_name and self.last_name:
            return f'{self.first_name} {self.last_name}'

        if self.email:
            return self.email

        return self.auth_user.username
예제 #6
0
class O2O_null(Model):
    name = fields.CharField(max_length=64)
    event: fields.OneToOneRelation[Event] = fields.OneToOneField(
        "models.Dest_null",
        on_delete=fields.CASCADE,
        related_name="address_null",
        null=True)
예제 #7
0
class StraightFields(Model):
    eyedee = fields.IntField(pk=True, description="Da PK")
    chars = fields.CharField(max_length=50,
                             index=True,
                             description="Some chars")
    blip = fields.CharField(max_length=50, default="BLIP")
    nullable = fields.CharField(max_length=50, null=True)

    fk: fields.ForeignKeyNullableRelation[
        "StraightFields"] = fields.ForeignKeyField("models.StraightFields",
                                                   related_name="fkrev",
                                                   null=True,
                                                   description="Tree!")
    fkrev: fields.ReverseRelation["StraightFields"]

    o2o: fields.OneToOneNullableRelation[
        "StraightFields"] = fields.OneToOneField("models.StraightFields",
                                                 related_name="o2o_rev",
                                                 null=True,
                                                 description="Line")
    o2o_rev: fields.Field

    rel_to: fields.ManyToManyRelation[
        "StraightFields"] = fields.ManyToManyField("models.StraightFields",
                                                   related_name="rel_from",
                                                   description="M2M to myself")
    rel_from: fields.ManyToManyRelation["StraightFields"]

    class Meta:
        unique_together = [["chars", "blip"]]
        table_description = "Straight auto-mapped fields"
예제 #8
0
class TeamAddress(Model):
    city = fields.CharField(max_length=50, description="City")
    country = fields.CharField(max_length=50, description="Country")
    street = fields.CharField(max_length=128, description="Street Address")
    team = fields.OneToOneField(
        "models.Team", related_name="address", on_delete=fields.CASCADE, pk=True
    )
예제 #9
0
class Address(Model):
    city = fields.CharField(max_length=64)
    street = fields.CharField(max_length=128)

    event: fields.OneToOneRelation[Event] = fields.OneToOneField(
        "models.Event", on_delete=fields.CASCADE, related_name="address", null=True
    )
예제 #10
0
class Botbakuadmin_product(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=64)
    slug_name = fields.CharField(max_length=64)
    img = fields.CharField(max_length=256)
    price = fields.SmallIntField()
    in_stock = fields.BooleanField(default=True)
    subcategory: fields.ForeignKeyRelation[
        Botbakuadmin_subcategory] = fields.ForeignKeyField(
            'models.Botbakuadmin_subcategory', on_delete=fields.CASCADE)
    beer: fields.OneToOneRelation[Botbakuadmin_beer] = fields.OneToOneField(
        'models.Botbakuadmin_beer', on_delete=fields.CASCADE)
    eat: fields.OneToOneRelation[Botbakuadmin_eat] = fields.OneToOneField(
        'models.Botbakuadmin_eat', on_delete=fields.CASCADE)

    def __repr__(self):
        return self.name
예제 #11
0
class VenueInformation(Model):
    name = fields.CharField(max_length=128)
    # This is just a comment
    #: No. of seats
    #: All this should not be part of the field description either!
    capacity = fields.IntField()
    rent = fields.FloatField()
    team = fields.OneToOneField("models.Team", on_delete=fields.SET_NULL, null=True)
예제 #12
0
class Principal(Model):
    id = fields.IntField(pk=True)
    name = fields.TextField()
    school: fields.OneToOneRelation[School] = fields.OneToOneField(
        "models.School",
        on_delete=fields.CASCADE,
        related_name="principal",
        to_field="id")
예제 #13
0
class Profile(models.Model):
    user = fields.OneToOneField('models.UserModel', related_name='profile')
    first_name = fields.CharField(max_length=50, null=True)
    last_name = fields.CharField(max_length=50, null=True)
    cities = fields.ManyToManyField('models.City', related_name='profiles')

    class PydanticMeta:
        exclude = ('user.email', 'user.hashed_password', 'user.is_active',
                   'user.confirmation')
예제 #14
0
class UUIDFkRelatedNullModel(Model):
    id = fields.UUIDField(pk=True)
    name = fields.CharField(max_length=50, null=True)
    model: fields.ForeignKeyNullableRelation[UUIDPkModel] = fields.ForeignKeyField(
        "models.UUIDPkModel", related_name=False, null=True
    )
    parent: fields.OneToOneNullableRelation[UUIDPkModel] = fields.OneToOneField(
        "models.UUIDPkModel", related_name=False, null=True
    )
예제 #15
0
class User(MosyneModel):
    """User model. aka `Guardian`

    Make reference to any user of application.
    The main class is a guardian, the person who
    take care of an angel.
    """

    email = fields.CharField(
        max_length=80,
        unique=True,
        index=True,
        description="User email address.",
    )

    password = fields.CharField(
        max_length=80,
        description="User hashed password.",
    )

    is_verified = fields.BooleanField(
        default=False,
        description="Indicates if user email is verified.",
    )

    firstname = fields.CharField(max_length=54)
    lastname = fields.CharField(max_length=54)

    phone = fields.CharField(
        max_length=16,
        description="User phone number.",
        default="",
    )

    cel = fields.CharField(
        max_length=16,
        description="User mobile number.",
        default="",
    )

    photo = fields.CharField(
        max_length=516,
        description="Url to user photo.",
        default="",
    )

    address = fields.OneToOneField(
        model_name="models.Address",
        on_delete=fields.CASCADE,
        description="FK to user address",
        null=True,
    )

    class Meta:
        """Meta info."""

        table = "users"
예제 #16
0
class SourceFields(Model):
    """
    A Docstring.
    """

    eyedee = fields.IntField(pk=True,
                             source_field="sometable_id",
                             description="Da PK")
    # A regular comment
    chars = fields.CharField(max_length=50,
                             source_field="some_chars_table",
                             index=True,
                             description="Some chars")
    #: A docstring comment
    blip = fields.CharField(max_length=50,
                            default="BLIP",
                            source_field="da_blip")
    nullable = fields.CharField(max_length=50,
                                null=True,
                                source_field="some_nullable")

    fk: fields.ForeignKeyNullableRelation[
        "SourceFields"] = fields.ForeignKeyField(
            "models.SourceFields",
            related_name="fkrev",
            null=True,
            source_field="fk_sometable",
            description="Tree!",
        )
    fkrev: fields.ReverseRelation["SourceFields"]

    o2o: fields.OneToOneNullableRelation[
        "SourceFields"] = fields.OneToOneField(
            "models.SourceFields",
            related_name="o2o_rev",
            null=True,
            source_field="o2o_sometable",
            description="Line",
        )
    o2o_rev: fields.Field

    rel_to: fields.ManyToManyRelation["SourceFields"] = fields.ManyToManyField(
        "models.SourceFields",
        related_name="rel_from",
        through="sometable_self",
        forward_key="sts_forward",
        backward_key="backward_sts",
        description="M2M to myself",
        on_delete=fields.NO_ACTION,
    )
    rel_from: fields.ManyToManyRelation["SourceFields"]

    class Meta:
        table = "sometable"
        unique_together = [["chars", "blip"]]
        table_description = "Source mapped fields"
예제 #17
0
class Accounts(CreatedModel):
    """
    계좌 테이블
    """
    id = fields.UUIDField(pk=True)
    balance = fields.IntField(default=0)
    modified = fields.DatetimeField(auto_now=True)
    customer_email = fields.OneToOneField(
        'models.Customers', related_name='CustomerToAccount', to_field='email'
    )
예제 #18
0
class Ration(models.Model):
    ration_id = fields.UUIDField(pk=True)
    meal: fields.ForeignKeyRelation[Meal] = fields.ForeignKeyField(
        "my_child.Meal",
        related_name="meal_rations",
        null=True,
        on_delete=fields.CASCADE,
    )
    food: fields.OneToOneRelation[Food] = fields.OneToOneField(
        "my_child.Food", related_name="food_rations", on_delete=fields.CASCADE)
    denial = fields.BooleanField()
예제 #19
0
class Catalog(Model):
    id = fields.IntField(pk=True)
    entry_code = fields.CharField(max_length=6)
    user = fields.OneToOneField('models.User', related_name='catalog')
    positions = fields.ManyToManyField('models.Position',
                                       related_name='catalog')

    class PydanticMeta:
        exclude = [
            'historys',
        ]
예제 #20
0
class Address(Model):
    city = fields.CharField(max_length=64)
    street = fields.CharField(max_length=128)

    event: fields.OneToOneRelation[Event] = fields.OneToOneField(
        "models.Event",
        on_delete=fields.CASCADE,
        related_name="address",
        primary_key=True)

    def __str__(self):
        return f"Address({self.city}, {self.street})"
예제 #21
0
class Student(models.Model):
    """The student model."""

    id = fields.UUIDField(pk=True)

    user = fields.OneToOneField("models.User",
                                related_name="students",
                                on_delete=fields.CASCADE)

    class Meta:
        """Meta data."""

        table = "student"
예제 #22
0
class TeamAddress(Model):
    """
    The Team's address

    This is a long section of the docs that won't appear in the description.
    """

    city = fields.CharField(max_length=50, description="City")
    country = fields.CharField(max_length=50, description="Country")
    street = fields.CharField(max_length=128, description="Street Address")
    team = fields.OneToOneField(
        "models.Team", related_name="address", on_delete=fields.CASCADE, pk=True
    )
예제 #23
0
class Address(Model):
    city = fields.CharField(max_length=64)
    street = fields.CharField(max_length=128)
    created_at = fields.DatetimeField(auto_now_add=True)

    event: fields.OneToOneRelation[Event] = fields.OneToOneField(
        "models.Event",
        on_delete=fields.CASCADE,
        related_name="address",
        pk=True)

    class Meta:
        ordering = ["city"]
예제 #24
0
class AdminUser(BaseModel, ModelMixin):
    user: fields.OneToOneRelation['User'] = fields.OneToOneField(
        model_name='models.User',
        related_name='admin_user',
        db_constraint=False,
        description='用户id')

    login_time = fields.DatetimeField(null=True, description='登录时间')
    token_expired = fields.DatetimeField(null=True, description='登录过期时间')

    class Meta:
        table = 'admin_users'
        table_description = '管理员表'
예제 #25
0
class Teacher(models.Model):
    """The teacher model."""

    id = fields.UUIDField(pk=True)

    user = fields.OneToOneField("models.User",
                                related_name="teachers",
                                on_delete=fields.CASCADE)

    class Meta:
        """Meta data."""

        table = "teacher"
예제 #26
0
class Statistics(Model):
    player: fields.OneToOneRelation[Player] = fields.OneToOneField(
        "models.Player",
        on_delete=fields.CASCADE,
        related_name="statistics",
        pk=True)
    worked_times = fields.BigIntField(default=0)
    researched_times = fields.BigIntField(default=0)
    hugs_given = fields.BigIntField(default=0)
    hugs_received = fields.BigIntField(default=0)
    made_vaccines = fields.BigIntField(default=0)
    heals = fields.BigIntField(default=0)
    been_eaten_times = fields.BigIntField(default=0)
    eaten_brains = fields.BigIntField(default=0)
class BusinessDetailModel(models.Model):
    name: str = fields.CharField(max_length=255, null=True)
    profile_url: str = fields.CharField(max_length=255, null=True)

    # age = fields.IntField(null=True)

    facilities: fields.ReverseRelation["Facility"]

    class Meta:
        table = "business_detail"

    user: fields.OneToOneRelation[UserModel] = fields.OneToOneField(
        "models.UserModel",
        related_name="business_detail",
        on_delete=fields.CASCADE,
        pk=True,
        unique=True)
class UserDetailModel(models.Model):

    name: str = fields.CharField(max_length=255, null=True)
    profile_url: str = fields.CharField(max_length=255, null=True)
    gender: str = fields.CharField(max_length=50, null=True)
    # age = fields.IntField(null=True)

    booking: fields.ManyToManyRelation["Booking"]

    class Meta:
        table = "user_detail"

    user: fields.OneToOneRelation[UserModel] = fields.OneToOneField(
        "models.UserModel",
        related_name="detail",
        on_delete=fields.CASCADE,
        pk=True)
예제 #29
0
파일: models.py 프로젝트: slyderc/lonr
class User(Model):
    id = fields.IntField(pk=True)
    username = fields.CharField(max_length=255, unique=True, index=True)
    password = fields.CharField(max_length=255)
    email = fields.CharField(max_length=255)
    is_admin = fields.BooleanField()
    can_chat = fields.BooleanField()

    # documents: fields.ReverseRelation["Document"]
    home: fields.OneToOneNullableRelation["Document"] = fields.OneToOneField(
        'models.Document', on_delete=fields.CASCADE, null=True)

    @classmethod
    async def new_user(cls, username, password, email, can_chat, is_admin):
        password = PASSWORD_CONTEXT.hash(password)
        user = await cls.create(
            username=username,
            password=password,
            email=email,
            can_chat=can_chat,
            is_admin=is_admin,
        )
        user_root = await Document.get_users()
        user_dir = await Document.create(
            segment=user.username,
            parent=user_root,
        )
        user.home = user_dir
        user_dir.owner = user
        await user_dir.save()
        await user.save()
        return user

    @classmethod
    async def get_user(cls, username):
        user = await cls.filter(username=username).first()
        return user

    def verify(self, password):
        return PASSWORD_CONTEXT.verify(password, self.password)

    def __repr__(self):
        return f"<{self.__class__.__name__}({self.username=}, password=..., {self.email=}, {self.is_admin=}, {self.can_chat=})>"

    def __str__(self):
        return self.username
예제 #30
0
class ChannelMember(models.Model):
    id = fields.IntField(pk=True)
    user: fields.OneToOneRelation[User] = fields.OneToOneField(
        "models.User",
        related_name="channel_members",
        on_delete=fields.CASCADE,
    )
    channel: fields.ForeignKeyRelation[Channel] = fields.ForeignKeyField(
        "models.Channel", related_name="channel_members")
    created_at = fields.DatetimeField(auto_now_add=True)
    updated_at = fields.DatetimeField(auto_now=True)

    class PydanticMeta:
        exclude = ["created_at", "updated_at"]

    def __str__(self):
        return f"Channel Member: {self.user.name} of channel {self.channel.name}"