[QUESTION] How to use serializers from other domains for nested relationships
See original GitHub issueWhile trying to implement the structure that you have posed, I have reached a point where I wonder what would be the best course of action:
In my use case, I have two domains, one that includes a User model, and another one that includes an Outfit model. I’m also using django serializers atm as they provide some helpers to ease development.
For my use case, I want to return the User model nested inside the Outfit model, but that would cross models between domains. What would be the best approach here?
from django.contrib.auth.models import User
from .models.look import Outfit
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ['username', 'email', 'url']
class OutfitSerializer(serializers.HyperlinkedModelSerializer):
user = UserSerializer()
class Meta:
model = Look
fields = ['shortcode', 'user', 'url']
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Django Rest Framework relationship queries in nested serializer
1 Answer 1 ; PlayerSerializer(serializers.Serializer): player_id = serializers.IntegerField() first_name = serializers.CharField(max_length=256) ...
Read more >Serializer relations - Django REST framework
Such nested relationships can be expressed by using serializers as fields. If the field is used to represent a to-many relationship, you should...
Read more >Unique constraint prevents nested serializers from updating
The workaround this is to remove the unique constraint from the serializer and move it to the business logic validation part since the...
Read more >Serializer Relations - Django REST Framework - GeeksforGeeks
In this section, we will discuss the different serializer relations provided by Django REST Framework Serializers. Table of Contents.
Read more >Frequently Asked Questions - RMI and Object Serialization
2 Why does my remote method or "callback" routine fail with a nested java.net.UnknownHostException ? C.3 My server is using a fully qualified...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is a good question, and one my team has struggled with solving too. I briefly looked at some solutions around the internet. Things like protocol buffers try and solve this by setting up a shared resource of schemas for data. My only concern with that is: you then have the problem of controlling the distribution of that protocol buffer.
We solved this (we === the team at my current employment) by having our own
UserSerializer
in our domain. Because it was “our” version of the User, even though the User came from a different domain.@pedrogimenez very good idea. I like it! Can you share any code examples? I can promote this issue into a question for prosperity.