Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix team update/create bugs #671

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions backend/siarnaq/api/teams/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Meta:
"auto_accept_unranked",
"eligible_for",
]
read_only_fields = ["rating", "has_avatar", "avatar_url"]
read_only_fields = ["rating", "has_avatar", "avatar_url", "has_report"]

def create(self, validated_data):
eligible_for = validated_data.pop("eligible_for", None)
Expand Down Expand Up @@ -114,19 +114,15 @@ def __call__(self, serializer_field):

class TeamPrivateSerializer(TeamPublicSerializer):
profile = TeamProfilePrivateSerializer(required=False)
episode = serializers.PrimaryKeyRelatedField(
default=CurrentEpisodeDefault(), queryset=Episode.objects.all()
)

class Meta:
model = Team
fields = ["id", "profile", "episode", "name", "members", "join_key", "status"]
read_only_fields = ["id", "name", "members", "join_key", "status"]
read_only_fields = ["id", "episode", "name", "members", "join_key", "status"]

@transaction.atomic
def create(self, validated_data):
team = Team.objects.create(**validated_data)

# Add self to team
request = self.context.get("request")
team.members.add(request.user)
Expand All @@ -142,6 +138,10 @@ def update(self, instance, validated_data):


class TeamCreateSerializer(TeamPrivateSerializer):
episode = serializers.PrimaryKeyRelatedField(
default=CurrentEpisodeDefault(), queryset=Episode.objects.all()
)

class Meta:
model = Team
fields = ["id", "profile", "episode", "name", "members", "join_key", "status"]
Expand Down