From 031486fd5d15956308b21255e40a1017d93ab0e0 Mon Sep 17 00:00:00 2001 From: TheoLechemia Date: Wed, 13 Dec 2023 14:11:13 +0100 Subject: [PATCH] add price - ref #3587 --- geotrek/api/tests/test_v2.py | 2 +- geotrek/api/v2/serializers.py | 2 +- geotrek/tourism/forms.py | 3 ++- .../migrations/0050_touristicevent_price.py | 19 +++++++++++++++++++ geotrek/tourism/models.py | 7 +++++++ .../touristicevent_detail_attributes.html | 4 ++++ geotrek/tourism/views.py | 2 +- 7 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 geotrek/tourism/migrations/0050_touristicevent_price.py diff --git a/geotrek/api/tests/test_v2.py b/geotrek/api/tests/test_v2.py index e589583eb1..cdc35b87aa 100644 --- a/geotrek/api/tests/test_v2.py +++ b/geotrek/api/tests/test_v2.py @@ -230,7 +230,7 @@ 'description', 'description_teaser', 'districts', 'duration', 'email', 'end_date', 'external_id', 'geometry', 'meeting_point', 'start_time', 'meeting_time', 'end_time', 'name', 'organizer', 'organizer_id', 'capacity', 'pdf', 'place', 'portal', 'practical_info', 'provider', 'published', 'source', 'speaker', 'structure', 'target_audience', 'themes', - 'type', 'update_datetime', 'url', 'uuid', 'website', 'cancelled', 'cancellation_reason', 'participant_number' + 'type', 'update_datetime', 'url', 'uuid', 'website', 'cancelled', 'cancellation_reason', 'participant_number', 'price' ]) TOURISTIC_EVENT_PLACE_DETAIL_JSON_STRUCTURE = sorted([ diff --git a/geotrek/api/v2/serializers.py b/geotrek/api/v2/serializers.py index 1ac6b09b9a..d8434c0578 100644 --- a/geotrek/api/v2/serializers.py +++ b/geotrek/api/v2/serializers.py @@ -554,7 +554,7 @@ class Meta(TimeStampedSerializer.Meta): 'meeting_time', 'name', 'organizer', 'organizer_id', 'participant_number', 'pdf', 'place', 'portal', 'practical_info', 'provider', 'published', 'source', 'speaker', 'start_time', 'structure', 'target_audience', 'themes', 'type', - 'url', 'uuid', 'website' + 'url', 'uuid', 'website', 'price' ) class TouristicEventPlaceSerializer(serializers.ModelSerializer): diff --git a/geotrek/tourism/forms.py b/geotrek/tourism/forms.py index a92670a311..de29723bd5 100644 --- a/geotrek/tourism/forms.py +++ b/geotrek/tourism/forms.py @@ -84,6 +84,7 @@ class TouristicEventForm(CommonForm): 'start_time', 'end_time', 'duration', + 'price', 'place', 'meeting_point', 'description_teaser', @@ -132,7 +133,7 @@ class Meta: 'start_time', 'end_time', 'contact', 'email', 'website', 'organizer', 'speaker', 'type', 'accessibility', 'capacity', 'booking', 'target_audience', 'practical_info', 'approved', 'source', 'portal', 'geom', 'eid', 'structure', 'bookable', - 'cancelled', 'cancellation_reason', 'preparation_duration', 'intervention_duration'] + 'cancelled', 'cancellation_reason', 'preparation_duration', 'intervention_duration', 'price'] model = TouristicEvent widgets = {'geom': AutoLocateMapWidget()} diff --git a/geotrek/tourism/migrations/0050_touristicevent_price.py b/geotrek/tourism/migrations/0050_touristicevent_price.py new file mode 100644 index 0000000000..df51f4be01 --- /dev/null +++ b/geotrek/tourism/migrations/0050_touristicevent_price.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.23 on 2023-12-13 12:42 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tourism', '0049_alter_touristiccontentcategory_color'), + ] + + operations = [ + migrations.AddField( + model_name='touristicevent', + name='price', + field=models.FloatField(blank=True, help_text='0 mean free', null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Price'), + ), + ] diff --git a/geotrek/tourism/models.py b/geotrek/tourism/models.py index 5b685ba716..72fdb988d1 100644 --- a/geotrek/tourism/models.py +++ b/geotrek/tourism/models.py @@ -458,6 +458,13 @@ class TouristicEvent(ZoningPropertiesMixin, AddPropertyMixin, PublishableMixin, help_text=_("In hours (1.5 = 1 h 30, 24 = 1 day, 48 = 2 days)"), validators=[MinValueValidator(0)] ) + price = models.FloatField( + null=True, + blank=True, + verbose_name=_("Price"), + help_text=_("0 mean free"), + validators=[MinValueValidator(0)] + ) objects = TouristicEventManager() place = models.ForeignKey(TouristicEventPlace, related_name="touristicevents", verbose_name=_("Event place"), on_delete=models.PROTECT, null=True, blank=True, help_text=_("Select a place in the list or locate the event directly on the map")) id_prefix = 'E' diff --git a/geotrek/tourism/templates/tourism/touristicevent_detail_attributes.html b/geotrek/tourism/templates/tourism/touristicevent_detail_attributes.html index f23b02b5a7..0f40de100f 100644 --- a/geotrek/tourism/templates/tourism/touristicevent_detail_attributes.html +++ b/geotrek/tourism/templates/tourism/touristicevent_detail_attributes.html @@ -46,6 +46,10 @@

{% trans "Attributes" %}

{{ object|verbose:"duration" }} {{ object.duration }} + + {{ object|verbose:"price" }} + {{ object.price }} + {{ object|verbose:"meeting_point" }} {{ object.meeting_point }} diff --git a/geotrek/tourism/views.py b/geotrek/tourism/views.py index 9119e031df..2292303eb8 100644 --- a/geotrek/tourism/views.py +++ b/geotrek/tourism/views.py @@ -206,7 +206,7 @@ class TouristicEventFormatList(MapEntityFormat, TouristicEventList): 'review', 'published', 'publication_date', 'cities', 'districts', 'areas', 'approved', 'uuid', 'cancelled', 'cancellation_reason', 'total_participants', 'place', - 'preparation_duration', 'intervention_duration', + 'preparation_duration', 'intervention_duration', 'price' ] def get_queryset(self):