tortoise / tortoise/tortoise-orm
Editable=False field
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Is your feature request related to a problem? Please describe.
In many cases it is useful to automatically add a value to a field that cannot be changed by the user, but can be shown. An example of this is the created_at field, which uses the auto_now_add=True in order to set the field to not be editable. It is thus not shown in the input of a POST request, but is part of the return value.
This is what I've found searching for a solution: https://stackoverflow.com/questions/50603619/why-datetimefield-with-auto-now-add-can-not-get-in-form-fields, which describes my problem and the potential solution, but tackles it with supported functionalities which do not work in my case.
Describe the solution you'd like
The possibility to "hide" a field from the input and to not accept any value, but to show that field in the return. Like with created = fields.DatetimeField(auto_now_add=True), but also for other fields. In my case it's the author which is stored in the JWT token which should be not submittable by the user, but be present in the returned object (JSON since rest api).
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
OS: Ubuntu 21.04
Tortoise: 0.16.20
DB: Postgresql
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named. Start by tracing fields.DatetimeField and auto_now_add=True through model input and JSON output handling, then determine how a JWT-derived author could be excluded from submitted values while remaining visible in returned objects. Done means a non-editable field rejects user input, is omitted from input representation, and appears in output representation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- api, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100