Skip to content
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

resolve timedelta field doesn't work #1362

Open
jankrnavek opened this issue Dec 15, 2024 · 0 comments
Open

resolve timedelta field doesn't work #1362

jankrnavek opened this issue Dec 15, 2024 · 0 comments

Comments

@jankrnavek
Copy link

jankrnavek commented Dec 15, 2024

In WorkerOut ModelSchema bellow I am not get to work pydantic field resolve_runtime_sec that converts timedelta orm field to seconds.
For debug purposes I added a row that works correctly.

Thanks,
H.

class WorkerOut(ModelSchema):
    runtime_sec: float = Field(0)

    @staticmethod
    def resolve_runtime_sec(obj) -> float:
        # print(obj.runtime.total_seconds())  # a debug row - a timedelta method that prints seconds correctly
        return obj.runtime.total_seconds()

    class Meta:
        model = Worker
        exclude = [
            "id",
            "runtime",
        ]
  • Python version: 3.12
  • Django version: 5.1
  • Django-Ninja version: 1.3
  • Pydantic version: 2.10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant