tortoise / tortoise/tortoise-orm

Editable=False field

Open
#640 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.