class User(ormar.Model):
            class Meta(MainMeta):
                pass

            registrationnumber: str = ormar.Text(primary_key=True)
            company: Company = ormar.ForeignKey(Company)
            company2: Company = ormar.ForeignKey(Company)
Ejemplo n.º 2
0
def adjust_through_many_to_many_model(model_field: Type["ManyToManyField"]) -> None:
    """
    Registers m2m relation on through model.
    Sets ormar.ForeignKey from through model to both child and parent models.
    Sets sqlalchemy.ForeignKey to both child and parent models.
    Sets pydantic fields with child and parent model types.

    :param model_field: relation field defined in parent model
    :type model_field: ManyToManyField
    """
    parent_name = model_field.default_target_field_name()
    child_name = model_field.default_source_field_name()

    model_field.through.Meta.model_fields[parent_name] = ormar.ForeignKey(
        model_field.to,
        real_name=parent_name,
        ondelete="CASCADE",
        owner=model_field.through,
    )
    model_field.through.Meta.model_fields[child_name] = ormar.ForeignKey(
        model_field.owner,
        real_name=child_name,
        ondelete="CASCADE",
        owner=model_field.through,
    )

    create_and_append_m2m_fk(
        model=model_field.to, model_field=model_field, field_name=parent_name
    )
    create_and_append_m2m_fk(
        model=model_field.owner, model_field=model_field, field_name=child_name
    )

    create_pydantic_field(parent_name, model_field.to, model_field)
    create_pydantic_field(child_name, model_field.owner, model_field)
Ejemplo n.º 3
0
class UserEnterprise(ormar.Model):
    class Meta(BaseMeta):
        tablename = "userenterprise"

    id = ormar.Integer(primary_key=True)
    enterprise_id = ormar.ForeignKey(Enterprise, ondelete="CASCADE")
    user_id = ormar.ForeignKey(User)
    role = ormar.String(max_length=10, choices=UserEnterpriseRoles)
Ejemplo n.º 4
0
class Follower(ormar.Model):
    class Meta(MainMata):
        pass

    id: int = ormar.Integer(primary_key=True)
    user: Optional[Union[User, Dict]] = ormar.ForeignKey(User,
                                                         related_name="user")
    subscriber: Optional[Union[User, Dict]] = ormar.ForeignKey(
        User, related_name="subscriber")
Ejemplo n.º 5
0
class Teacher(ormar.Model):
    class Meta:
        tablename = "teachers"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100)
    schoolclass: Optional[SchoolClass] = ormar.ForeignKey(SchoolClass)
    category: Optional[Category] = ormar.ForeignKey(Category, nullable=True)
class Item(ormar.Model):
    class Meta:
        tablename = "items"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100)
    category: Optional[Category] = ormar.ForeignKey(Category, nullable=True)
    created_by: Optional[User] = ormar.ForeignKey(User)
Ejemplo n.º 7
0
class InvoicePosition(ormar.Model):
    class Meta(BaseMeta):
        tablename = "invoiceposition"

    id = ormar.Integer(primary_key=True)
    name = ormar.String(max_length=50)
    vat_rate_id = ormar.ForeignKey(VatRate)
    num_items = ormar.Float()
    price_net = ormar.Float()
    invoice_id = ormar.ForeignKey(Invoice, ondelete="CASCADE")
Ejemplo n.º 8
0
class Translation(ormar.Model):
    class Meta(ormar.ModelMeta):
        tablename = "translations"
        database = database
        metadata = metadata

    translation_id = ormar.Integer(primary_key=True, autoincrement=True)
    node_id = ormar.ForeignKey(TranslationNode, related_name="translations")
    language = ormar.ForeignKey(Language, name="language_id")
    value = ormar.String(max_length=500)
Ejemplo n.º 9
0
class Invoice(ormar.Model):
    class Meta(BaseMeta):
        tablename = "invoice"

    id = ormar.Integer(primary_key=True)
    invoice_business_id = ormar.String(max_length=64)
    invoice_date = ormar.Date()
    invoice_type = ormar.String(max_length=8, choices=[])
    trading_partner_id = ormar.ForeignKey(TradingPartner)
    enterprise_id = ormar.ForeignKey(Enterprise, ondelete="CASCADE")
Ejemplo n.º 10
0
class FilterValue(ormar.Model):
    class Meta(ormar.ModelMeta):
        tablename = "filter_values"
        database = database
        metadata = metadata

    value_id = ormar.Integer(primary_key=True, autoincrement=True)
    value = ormar.String(max_length=300)
    label = ormar.String(max_length=300)
    filter = ormar.ForeignKey(Filter, name="filter_id", related_name="values")
    translation = ormar.ForeignKey(TranslationNode, name="translation_node_id")
Ejemplo n.º 11
0
class ChartXReport(ormar.Model):
    class Meta(ormar.ModelMeta):
        tablename = "charts_x_reports"
        database = database
        metadata = metadata

    chart_x_report_id = ormar.Integer(primary_key=True)
    chart = ormar.ForeignKey(Chart, name="chart_id", related_name="reports")
    report = ormar.ForeignKey(Report, name="report_id", related_name="charts")
    sort_order = ormar.Integer()
    width = ormar.Integer()
Ejemplo n.º 12
0
class Track(ormar.Model):
    class Meta:
        tablename = "tracks"
        metadata = metadata
        database = database

    id: int = ormar.Integer(name="track_id", primary_key=True)
    album: Optional[Album] = ormar.ForeignKey(Album)
    title: str = ormar.String(max_length=100)
    position: int = ormar.Integer()
    tonation: Optional[Tonation] = ormar.ForeignKey(Tonation, name="tonation_id")
Ejemplo n.º 13
0
class ChartColumn(ormar.Model):
    class Meta(ormar.ModelMeta):
        tablename = "charts_columns"
        database = database
        metadata = metadata

    column_id = ormar.Integer(primary_key=True, autoincrement=True)
    chart = ormar.ForeignKey(Chart, name="chart_id", related_name="columns")
    column_name = ormar.String(max_length=200)
    column_type = ormar.String(max_length=200)
    translation = ormar.ForeignKey(TranslationNode, name="translation_node_id")
Ejemplo n.º 14
0
class Track(ormar.Model):
    class Meta:
        tablename = "tracks"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    album: Optional[Album] = ormar.ForeignKey(Album)
    title: str = ormar.String(max_length=100)
    position: int = ormar.Integer()
    play_count: int = ormar.Integer(nullable=True)
    written_by: Optional[Writer] = ormar.ForeignKey(Writer)
Ejemplo n.º 15
0
class Claim(ormar.Model):
    class Meta(BaseMeta):
        tablename = "claims"
        constraints = [ormar.UniqueColumns('attendee', 'event')]

    id: int = ormar.Integer(primary_key=True)
    attendee: Attendee = ormar.ForeignKey(Attendee,
                                          nullable=True,
                                          skip_reverse=True)
    event: Event = ormar.ForeignKey(Event, skip_reverse=True)
    link: str = ormar.String(max_length=256)
    reserved: Optional[bool] = ormar.Boolean(default=False)
Ejemplo n.º 16
0
class FilterXReport(ormar.Model):
    class Meta(ormar.ModelMeta):
        tablename = "filters_x_reports"
        database = database
        metadata = metadata

    filter_x_report_id = ormar.Integer(primary_key=True)
    filter = ormar.ForeignKey(Filter, name="filter_id", related_name="reports")
    report = ormar.ForeignKey(Report, name="report_id", related_name="filters")
    sort_order = ormar.Integer()
    default_value = ormar.Text()
    is_visible = ormar.Boolean()
Ejemplo n.º 17
0
class Car(ormar.Model):
    class Meta:
        abstract = True
        metadata = metadata
        database = db

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=50)
    owner: Person = ormar.ForeignKey(Person)
    co_owner: Person = ormar.ForeignKey(Person, related_name="coowned")
    created_date: datetime.datetime = ormar.DateTime(
        default=datetime.datetime.now)
Ejemplo n.º 18
0
class Child(ormar.Model):
    class Meta(ModelMeta):
        metadata = metadata
        database = db

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100)
    favourite_game: GameRef = ormar.ForeignKey(GameRef,
                                               related_name="liked_by")
    least_favourite_game: GameRef = ormar.ForeignKey(
        GameRef, related_name="not_liked_by")
    friends = ormar.ManyToMany(ChildRef,
                               through=ChildFriendRef,
                               related_name="also_friends")
Ejemplo n.º 19
0
class CringeLevel(ormar.Model):
    class Meta(BaseMeta):
        tablename = "levels"

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100)
    language = ormar.ForeignKey(Language)
class CB2(ormar.Model):
    class Meta(BaseMeta):
        tablename = "cb2s"

    id: UUID = ormar.UUID(primary_key=True, default=uuid4)
    cb2_name: str = ormar.Text(default="")
    ca2: Optional[CA] = ormar.ForeignKey(CA, nullable=True)
Ejemplo n.º 21
0
class Filter(ormar.Model):
    class Meta(BaseMeta):
        tablename = "filters"

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100, **default_fernet)
    hash = ormar.ForeignKey(Hash)
class Task(ormar.Model):
    class Meta(BaseMeta):
        tablename = "task"

    id: int = ormar.Integer(primary_key=True, autoincrement=True, nullable=False)
    from_: str = ormar.String(name="from", nullable=True, max_length=200)
    user = ormar.ForeignKey(User)
class User(ormar.Model):
    class Meta(MainMeta):
        pass

    registrationnumber: str = ormar.String(primary_key=True, max_length=1000)
    company: Company = ormar.ForeignKey(Company)
    company2: Company = ormar.ForeignKey(Company,
                                         related_name="secondary_users")
    name: str = ormar.Text()
    role: Optional[Role] = ormar.ForeignKey(Role)
    roleforcompanies: Optional[Union[Company,
                                     List[Company]]] = ormar.ManyToMany(
                                         Company,
                                         through=UserRoleCompany,
                                         related_name="role_users")
    lastupdate: date = ormar.DateTime(server_default=sqlalchemy.func.now())
Ejemplo n.º 24
0
class Album(ormar.Model):
    class Meta(MainMeta):
        pass

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100)
    artist: Optional[Artist] = ormar.ForeignKey(Artist)
Ejemplo n.º 25
0
class Subject(DateFieldsModel):
    class Meta(ormar.ModelMeta):
        pass

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=50, unique=True, index=True)
    category: Optional[Category] = ormar.ForeignKey(Category)
Ejemplo n.º 26
0
class Book(ormar.Model):
    class Meta(BaseMeta):
        tablename = "books"

    id: int = ormar.Integer(primary_key=True)
    author: Optional[Author] = ormar.ForeignKey(Author)
    title: str = ormar.String(max_length=100)
    year: int = ormar.Integer(nullable=True)
Ejemplo n.º 27
0
class Company(ormar.Model):
    class Meta(BaseMeta):
        tablename = "companies"

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100, nullable=False, name="company_name")
    founded: int = ormar.Integer(nullable=True)
    hq: HQ = ormar.ForeignKey(HQ, related_name="companies")
Ejemplo n.º 28
0
class Post(ormar.Model):
    class Meta(BaseMeta):
        pass

    id: int = ormar.Integer(primary_key=True)
    title: str = ormar.String(max_length=200)
    categories = ormar.ManyToMany(Category, skip_reverse=True)
    author: Optional[Author] = ormar.ForeignKey(Author, skip_reverse=True)
Ejemplo n.º 29
0
class Bus(Car):
    class Meta:
        tablename = "buses"
        metadata = metadata
        database = db

    owner: Person = ormar.ForeignKey(Person, related_name="buses")
    max_persons: int = ormar.Integer()
Ejemplo n.º 30
0
class TrackArtist(ormar.Model):
    """
    `tracks_artists` table mapping.

    Attributes
    ----------
        id: str, primary key
        artist: Artist, foreign key
        track: Track, foreign key
    """

    class Meta(BaseMeta):
        pass

    id: str = ormar.Integer(primary_key=True, autoincrement=True)
    artist: Artist = ormar.ForeignKey(Artist)
    track: Track = ormar.ForeignKey(Track)