Bishwas-py / djapy

No bullshit, Django Rest API Framework
https://djapy.io
61 stars 3 forks source link

`content_type` clashes with model schema `content_type` #28

Closed Bishwas-py closed 3 months ago

Bishwas-py commented 3 months ago

I am trying to return content type of my model via this inheritable schema:

class HasContentType(Schema):
    content_type: int

    @field_validator('content_type', mode="before")
    def validate_content_type(cls, content_type):
        print("content_type> ", content_type)
        print(content_type, "content_type.id> ", content_type.id)
        return content_type.id

but it clashes with

class Schema(BaseModel):
    """
    Enhance to automatically detect many-to-many fields for serialization.
    """
    model_config = ConfigDict(validate_default=True, validate_assignment=True, from_attributes=True,
                              arbitrary_types_allowed=True)
    content_type: ClassVar = "application/json" # here
    description: ClassVar[dict] = {}

I think renaming content_type to something else is required.

Bishwas-py commented 3 months ago

650974b1ab7783dae2b958802dd26a3e48f1d7c5 fixed it.