I am attempting to use Django Ninja for the first time and running into a strange error
I cant quite understand error I am receiving. I am simply trying to setup a model schema for my model. I am an old Django hand but ninja is new for me. What am I doing wrong here? Would love some help and feedback.
My model is this
class Program(models.Model):
mentor = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
description = models.TextField()
start_date = models.DateField()
end_date = models.DateField()
attendees = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name="attendees")
participants = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name="participants")
created_on = models.DateTimeField(auto_now_add = True)
updated_on = models.DateTimeField(auto_now = True)
My api.py has the following definition
class MentorOutSchema(ModelSchema):
class Config:
model = Program
model_fields = [
"mentor",
"description",
"start_date",
"end_date",
"attendees",
"participants",
]
My endpoint is this
@router.get('/programs')
async def mentor_programs(request, response=list[MentorOutSchema]):
return Program.objects.filter(mentor=request.user)
When I start the server, I get the following error
@router.get('/programs')
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vivekv/.cache/pypoetry/virtualenvs/pifnow-Zp6OiFzb-py3.12/lib/python3.12/site-packages/ninja/router.py", line 268, in decorator
self.add_api_operation(
File "/home/vivekv/.cache/pypoetry/virtualenvs/pifnow-Zp6OiFzb-py3.12/lib/python3.12/site-packages/ninja/router.py", line 319, in add_api_operation
path_view.add_operation(
File "/home/vivekv/.cache/pypoetry/virtualenvs/pifnow-Zp6OiFzb-py3.12/lib/python3.12/site-packages/ninja/operation.py", line 426, in add_operation
operation = OperationClass(
^^^^^^^^^^^^^^^
File "/home/vivekv/.cache/pypoetry/virtualenvs/pifnow-Zp6OiFzb-py3.12/lib/python3.12/site-packages/ninja/operation.py", line 331, in __init__
super().__init__(*args, **kwargs)
File "/home/vivekv/.cache/pypoetry/virtualenvs/pifnow-Zp6OiFzb-py3.12/lib/python3.12/site-packages/ninja/operation.py", line 82, in __init__
self.signature = ViewSignature(self.path, self.view_func)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vivekv/.cache/pypoetry/virtualenvs/pifnow-Zp6OiFzb-py3.12/lib/python3.12/site-packages/ninja/signature/details.py", line 87, in __init__
self.models: TModels = self._create_models()
^^^^^^^^^^^^^^^^^^^^^
File "/home/vivekv/.cache/pypoetry/virtualenvs/pifnow-Zp6OiFzb-py3.12/lib/python3.12/site-packages/ninja/signature/details.py", line 171, in _create_models
model_cls = type(cls_name, (base_cls,), attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vivekv/.cache/pypoetry/virtualenvs/pifnow-Zp6OiFzb-py3.12/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 219, in __new__
set_model_fields(cls, bases, config_wrapper, ns_resolver)
File "/home/vivekv/.cache/pypoetry/virtualenvs/pifnow-Zp6OiFzb-py3.12/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 537, in set_model_fields
fields, class_vars = collect_model_fields(cls, bases, config_wrapper, ns_resolver, typevars_map=typevars_map)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vivekv/.cache/pypoetry/virtualenvs/pifnow-Zp6OiFzb-py3.12/lib/python3.12/site-packages/pydantic/_internal/_fields.py", line 220, in collect_model_fields
_warn_on_nested_alias_in_annotation(ann_type, ann_name)
File "/home/vivekv/.cache/pypoetry/virtualenvs/pifnow-Zp6OiFzb-py3.12/lib/python3.12/site-packages/pydantic/_internal/_fields.py", line 258, in _warn_on_nested_alias_in_annotation
for anno_arg in args:
^^^^
TypeError: 'member_descriptor' object is not iterable