Answer the question
In order to leave comments, you need to log in
Why does the serializer work differently?
Hello everybody!
I have several serializers:
User_avatar_serializer.py:
from rest_framework import serializers
from users.models import UserAvatar:
class UserAvatarSerializer(serializers.ModelSerializer):
class Meta:
model = UserAvatar
fields = [
"local_url",
]
def to_representation(self, instance):
ret = super().to_representation(instance)
return ret["local_url"]
from rest_framework import serializers
from api.users.serializers.user_avatar_serializer import UserAvatarSerializer
from users.models import User
class UserShortSerializer(serializers.ModelSerializer):
avatar = UserAvatarSerializer(required=False, read_only=True)
class Meta:
model = User
fields = [
"id",
"username",
"first_name",
"last_name",
"avatar",
"first_time",
]
...
"avatar": " 127.0.0.1:8000/media/user/avatar/1bbcd0e1-b7a8-44f... ",
...
def to_representation(self, instance):
...
ret["participants_info"] = {
...
"avatars": UserAvatarSerializer(instance=avatar_list, many=True, required=False).data,
...
}
return ret
...
"avatars": [
"/media/home/app/marathon/static/images/bg01.jpg"
],
...
avatar = UserAvatarSerializer(required=False, read_only=True)
UserAvatarSerializer(instance=avatar_list, many=True, required=False).data,
Answer the question
In order to leave comments, you need to log in
I did not specify the context in which the request should be forwarded.
More details in the documentation: https://www.django-rest-framework.org/api-guide/se...
Use CouchDB on the server
. On the PouchDB client, there are implementations for Browsers, Android, IOS (if you wish, you can probably screw it under the desktop)
https://pouchdb.com/faq.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question