-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add file model and display uploaded files
- Loading branch information
Showing
7 changed files
with
85 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from dataclasses import dataclass, fields | ||
from functools import partial | ||
|
||
from sqlalchemy import ForeignKey | ||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
from sqlalchemy.types import Uuid, String | ||
from uuid_extensions import uuid7 | ||
|
||
from rainfall.db import db | ||
|
||
|
||
@dataclass | ||
class File(db.Model): | ||
__tablename__ = 'files' | ||
|
||
id: Mapped[bytes] = mapped_column(Uuid, primary_key=True, default=uuid7) | ||
release_id: Mapped[bytes] = mapped_column(ForeignKey("releases.id")) | ||
release: Mapped["Release"] = relationship(back_populates="files") | ||
filename: Mapped[str] = mapped_column(String(1024)) | ||
|
||
def __repr__(self) -> str: | ||
return f'File(id={self.id!r}, release_id={self.release_id!r})' | ||
|
||
def serialize(self): | ||
return dict((field.name, getattr(self, field.name)) | ||
for field in fields(self) | ||
if field.name != 'release') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters