async def post(self, *args, **kwargs) -> Response: json_body = await self.deserialize_body() team = Team() name = json_body.get('name') if name: team.name = name user_ids = json_body['users'] users = [] for user_id in user_ids: user = User.get_item(int(user_id)) if not user: raise UserNotFound users.append(user) team.users = users team.save() result = await self.serialize(data=team) return await self.to_response(result, status_code=201)
def create(self, validated_data): team = Team(**validated_data) team.save() team.users.add(self.context["request"].user) team.save() return team