You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#Schema.py
from ninja import ModelSchema
from .models import ClassDetail, Student
class ClassSchema(ModelSchema):
class Config:
model = ClassDetail
model_fields = "__all__"
arbitrary_types_allowed=True
class StudentSchema(ModelSchema):
classs: ClassSchema
class Config:
model = Student
model_fields = '__all__'
and api routes
#api.py
from typing import List
from ninja import Router
from .models import Student, ClassDetail
from .schema import ClassSchema, StudentSchema
router = Router()
@router.post('/class', response=ClassSchema)
def create_clas(request, payload=ClassSchema):
clas = ClassDetail.objects.create(**payload.dict())
return clas
@router.get('/student', response=List[StudentSchema])
def get_students(request):
schema = Student.objects.all()
return schema
@router.post('/student', response=StudentSchema)
def create_student(request, payload: StudentSchema):
stu = Student.objects.create(**payload.dict())
return stu
when trying to run the server i am getting this error
pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'ninja.orm.metaclass.ModelSchemaMetaclass'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.
If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.
Versions
Python version: [3.9]
Django version: [5.0.4]
Django-Ninja version: [1.1.0]
Pydantic version: [2.7.1]
pydantic core version: [2.18.2]
The text was updated successfully, but these errors were encountered:
Describe the bug
I have django models
and Ninja Schema
and api routes
when trying to run the server i am getting this error
Versions
The text was updated successfully, but these errors were encountered: