Open gurbaaz27 opened 1 year ago
You might need to make a custom class for points, like this.
@OtherBarry thanks for the resource.
Right now I am extending TYPES
like this. Is this the correct way to do?
from ninja.orm.fields import TYPES
from stores.models import Store
class PointClass(Point):
@classmethod
def __get_validators__(cls):
yield cls.validate
@classmethod
def validate(cls, v):
return cls(v)
@classmethod
def __modify_schema__(cls, field_schema):
field_schema.update(type="tuple", example=(22.5, 22.5))
def __repr__(self):
return f"PointField({super().__repr__()})"
TYPES.update({"PointField": PointClass})
class StoreSchema(ModelSchema):
class Config:
model = Store
model_fields = "__all__"
I haven't tested the API, but running the server doesn't throw any error.
Please describe what you are trying to achieve I have a Django model with a location field (which is a PointField), and I am trying to generate schema from it using ModelSchema, but I guess django-ninja doesn't have support for these geofields. I wanted to know if I am doing an error, or is there any hack around the same? Thanks.
Please include code examples (like models code, schemes code, view function) to help understand the issue
models.py
schema.py
Error