Skip to content

Update embedded_model.py #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update embedded_model.py #351

wants to merge 1 commit into from

Conversation

ddrondo
Copy link

@ddrondo ddrondo commented Jul 29, 2025

In the django serializer, without this feature, you need to wrap dict in Embedded models yourself.

@timgraham
Copy link
Collaborator

timgraham commented Jul 29, 2025

Hi Dmitriy, Thanks for the report and patch. Can you give more details about how to reproduce the problem? We haven't added dumpdata / loaddata support for embedded models yet (#243), however, I'm not sure if you're referring to that issue or to something else (possibly Django rest framework serializers?). I'm skeptical we should automatically convert dictionaries to model instances in EmbeddedModelField.get_db_prep_save() as you proposed.

@ddrondo
Copy link
Author

ddrondo commented Jul 30, 2025

Automatic conversion is very convenient when there are one or more nested serializers

class UserSerializer(serializers.ModelSerializer):
- .... another serializer
- .... another serializer

Instead of manually overriding def create, def update in ModelSerializer. It especially simplifies the process when there are many nested serializers in the nested ones. Imagine 2, 3, 10, ... nesting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants