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
I am using django, django-ninja framework to replace some of my apis ( written in drf, as it is becoming more like a boilerplate codebase ). Now while transforming some legacy api to django-ninja, I need to follow the old structure, so the client side doesn't face any issue. Django-ninja helped a lot to reduce a lot of boilerplate codes and helped to increase the code readability. This is just the backstory.
Now coming to the issue:
I have two separate models.
classAuthor(models.Model):
username=models.CharField(...)
email=models.CharField(...)
... # Other fieldsclassBlog(models.Model):
title=models.CharField(...)
text=models.CharField(...)
tags=models.CharField(...)
author=models.ForeignKey(...)
... # Other fields
The structure written in django rest framework serializer
But as you can see, drf serializer has a parameter called source, where source="*" means to pass the entire original dataset to the nested field serializer. Is there any option to do the exact same with pydantic?
Except for creating a list of dictionaries [{author: blog.author, "blog": blog} for blog in queryset]
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am using django, django-ninja framework to replace some of my apis ( written in drf, as it is becoming more like a boilerplate codebase ). Now while transforming some legacy api to django-ninja, I need to follow the old structure, so the client side doesn't face any issue. Django-ninja helped a lot to reduce a lot of boilerplate codes and helped to increase the code readability. This is just the backstory.
Now coming to the issue:
I have two separate models.
The structure written in django rest framework serializer
In viewset the following queryset will be passed
I have the following code for pydantic/ninja schema
But as you can see, drf serializer has a parameter called
source
, wheresource="*"
means to pass the entire original dataset to the nested field serializer. Is there any option to do the exact same with pydantic?Except for creating a list of dictionaries
[{author: blog.author, "blog": blog} for blog in queryset]
Beta Was this translation helpful? Give feedback.
All reactions