jordaneremieff / djantic

Pydantic model support for Django
https://github.com/jordaneremieff/djantic
MIT License
457 stars 34 forks source link

String Related Fields #58

Closed Lucasmiguelmac closed 2 years ago

Lucasmiguelmac commented 2 years ago

Hello there!

Is there yet a way to use something like DRF's string-related field? That is, for a model field with a relation, set it to a custom field that returns the related model's string representation.

Lucasmiguelmac commented 2 years ago

Already figured. This can be achieved by doing the following:

class MySchema(ModelSchema):
    ...
    @validator("my_field", check_fields=False)
    def format_my_field(cls, v):
        return some_changed_value