-
Notifications
You must be signed in to change notification settings - Fork 83
Use SQLAlchemy defaults in fields #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Related to #491 |
|
Sorry, @hasansezertasan, any updates on this PR? |
It's OK. I was the one who volunteered but I couldn't get my hands free for this. I'll work on it when I get a chance. |
starlette_admin/fields.py
Outdated
| id: str = "" | ||
| search_builder_type: Optional[str] = "default" | ||
| required: Optional[bool] = False | ||
| default: str = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| default: str = "" | |
| default: Optional[Any] = None |
|
Thank you, @geoolekom, for submitting this pull request. Would you be interested in implementing it for other backends as well? |
f17d460 to
0c1ad9d
Compare
Unfortunately, for now I don't have much time to implement other backends in this PR. Perhaps later, in a separate pull request. For now, I fixed failed CI checks for SQLA backend. Could you trigger the pipeline again? |
ca3699e to
a0da93d
Compare
|
Hi, I'm wondering if there's any work remaining on this that I could assist with. It would be nice to have for a project I'm working on. |
jowilf
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry @geoolekom for taking to long to review. it looks good, we just need to solve conflicts with the base branch
|
Still missing default in CollectionField and ListField I think it can be done like this @dataclass(init=False)
class CollectionField(BaseField):
....
def __init__(
self, name: str, fields: Sequence[BaseField], required: bool = False
) -> None:
self.name = name
self.fields = fields
self.required = required
self.default = {field.name: field.default for field in fields} # Set default values
super().__post_init__()
self._propagate_id() |
Now, if a SQLA Column has a default value, it is used in the admin panel. If it is a scalar, then the value is used directly. If it is a function or SQL expression, the extra help text is displayed.