Skip to content

[QUESTION] How to use serializers from other domains for nested relationships #12

Open
@juanxo

Description

@juanxo

While 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']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions