def create(self, validated_data):
target_languages = validated_data.pop('target_languages')
user = User.objects.create(**validated_data)
for target_language in target_languages:
user.target_languages.add(get_object_or_404(Language, iso_639_1=target_language))
user.save()
return user
<?xml version="1.0" encoding="utf-8"?>
<response status="ok">
<products total="14">
<product>
<product_id>1</product_id>
<name>Product Name</name>
<description>Full Product Description</description>
<price>113.90</price>
<status>Coming Soon</status>
<tags>toys, kids, speedcar, racer</tags>
<shippable>yes</shippable>
<downloadable>no</downloadable>
<taxable>yes</taxable>
<categories>
<category category_id="149">Toys</category>
</categories>
</product>
....
</products>
</response>
class UserSearchSerializer(serializers.ModelSerializer):
info = UserProfileSerializer(many=True, read_only=True)
follow = serializers.SerializerMethodField('check_follow')
like = serializers.SerializerMethodField('check_like')
def check_follow(self, obj):
user_id = self.context.get("user_id")
user_has_followed = False
try:
user_has_followed = Follow.objects.filter(user_who_follow_id=user_id,
user_whom_follow_id=obj).exists()
except Exception:
raise user_has_followed
return user_has_followed
def check_like(self, obj):
user_id = self.context.get("user_id")
user_has_like = False
try:
user_has_like = Like.objects.filter(user_who_like_id=user_id,
user_whom_like_id=obj).exists()
except Exception:
raise user_has_like
return user_has_like
class Meta:
model = User
fields = ('id', 'username', 'first_name', 'last_name', 'email', 'info', 'follow', 'like')
[uwsgi]
socket = /home/ubuntu/contacts/project/contacts.sock
virtualenv = /home/ubuntu/contacts/ENV
chdir = /home/ubuntu/contacts/project
master = True
workers = 8
module = project.wsgi:application
plugin = python
uid = www-data
gid = www-data
chmod-socket = 777
chown-socket = www-data