Skip to content

Commit

Permalink
feat: deletephoto
Browse files Browse the repository at this point in the history
  • Loading branch information
jillro committed Jul 18, 2024
1 parent bff4af5 commit 9dbc67a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions annuaire/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class Meta:


class MemberSerializer(serializers.ModelSerializer):
delete_photo = serializers.BooleanField(
write_only=True, required=False, default=False
)

def validate_skills(self, skills):
if len(skills) > 6:
Expand Down Expand Up @@ -54,6 +57,19 @@ def __init__(self, *args, **kwargs):
self.fields["email"].write_only = True
self.fields["birth_year"].write_only = True

def update(self, instance, validated_data):
delete_photo = validated_data.pop("delete_photo", False)
photo = validated_data.get("photo")

if delete_photo:
instance.photo.delete()
instance.photo = None

if photo:
instance.photo = photo

return super().update(instance, validated_data)

def to_representation(self, instance):
ret = super().to_representation(instance)
request = self.context.get("request")
Expand Down Expand Up @@ -86,6 +102,7 @@ class Meta:
"gender",
"email",
"photo",
"delete_photo",
"languages",
"short_bio",
"institution",
Expand Down

0 comments on commit 9dbc67a

Please sign in to comment.