- diff --git a/eventplanner/serializers.py b/eventplanner/serializers.py index d17a164..c915f50 100644 --- a/eventplanner/serializers.py +++ b/eventplanner/serializers.py @@ -9,8 +9,8 @@ class ParticipationSerializer(serializers.Serializer): event = serializers.PrimaryKeyRelatedField(queryset=Event.objects.all()) user = serializers.CharField() - status = serializers.CharField(required=False, default="-") - comment = serializers.CharField(required=False, allow_blank=True, default="") + status = serializers.CharField(required=False) + comment = serializers.CharField(required=False, allow_blank=True) def to_representation(self, instance): """Serialize an EventParticipation instance.""" @@ -32,14 +32,19 @@ class ParticipationSerializer(serializers.Serializer): """Create or update EventParticipation based on event and user.""" event = validated_data.get("event") user = validated_data.get("user") - status = validated_data.get("status", "-") - comment = validated_data.get("comment", "") - # Use update_or_create to handle both new and existing participations + # Only include fields that were actually present in the request, + # so a status-only update doesn't wipe the comment (and vice versa). + defaults = {} + if "status" in validated_data: + defaults["status"] = validated_data["status"] + if "comment" in validated_data: + defaults["comment"] = validated_data["comment"] + participation, created = EventParticipation.objects.update_or_create( event=event, user=user, - defaults={"status": status, "comment": comment}, + defaults=defaults, ) return participation diff --git a/eventplanner/templates/eventplanner/event_update_form.html b/eventplanner/templates/eventplanner/event_update_form.html index 2fcd289..c279082 100644 --- a/eventplanner/templates/eventplanner/event_update_form.html +++ b/eventplanner/templates/eventplanner/event_update_form.html @@ -1,4 +1,7 @@ -{% extends "website/base.html" %} {% load sekizai_tags static %} {% load crispy_forms_tags %} {% block content %} {{ form.media }} +{% extends "website/base.html" %} {% load sekizai_tags static %} {% load crispy_forms_tags %} +{% block content %} +{% addtoblock "css" %}{% for item in form.media.render_css %}{{ item }}{% endfor %}{% endaddtoblock %} +{% addtoblock "js" %}{% for item in form.media.render_js %}{{ item }}{% endfor %}{% endaddtoblock %}
-