diff --git a/lego/apps/surveys/migrations/0013_survey_is_template.py b/lego/apps/surveys/migrations/0013_survey_is_template.py new file mode 100644 index 000000000..52ae5f098 --- /dev/null +++ b/lego/apps/surveys/migrations/0013_survey_is_template.py @@ -0,0 +1,20 @@ +from django.db import migrations, models + +def set_is_template(apps, schema_editor): + Survey = apps.get_model("surveys", "Survey") + Survey.objects.filter(template_type__isnull=False).update(is_template=True) + +class Migration(migrations.Migration): + + dependencies = [ + ("surveys", "0012_alter_survey_template_type"), + ] + + operations = [ + migrations.AddField( + model_name="survey", + name="is_template", + field=models.BooleanField(default=False), + ), + migrations.RunPython(set_is_template), + ] diff --git a/lego/apps/surveys/models.py b/lego/apps/surveys/models.py index a8fc0b8b2..7831235bf 100644 --- a/lego/apps/surveys/models.py +++ b/lego/apps/surveys/models.py @@ -25,6 +25,7 @@ class Survey(BasisModel): template_type = models.CharField( max_length=30, choices=EVENT_TYPES, null=True, blank=True, unique=True ) + is_template = models.BooleanField(default=False, null=False) event = models.OneToOneField("events.Event", on_delete=models.CASCADE) sent = models.BooleanField(default=False) token = models.CharField( diff --git a/lego/apps/surveys/serializers.py b/lego/apps/surveys/serializers.py index c0d2625a6..3addad9b9 100644 --- a/lego/apps/surveys/serializers.py +++ b/lego/apps/surveys/serializers.py @@ -87,7 +87,7 @@ class SurveyReadSerializer(BasisModelSerializer): class Meta: model = Survey - fields = ("id", "title", "active_from", "event", "template_type") + fields = ("id", "title", "active_from", "event", "template_type", "is_template") class SubmissionReadSerializer(BasisModelSerializer): @@ -144,7 +144,7 @@ class SurveyReadDetailedSerializer(BasisModelSerializer): class Meta: model = Survey - fields = ("id", "title", "active_from", "questions", "event", "template_type") + fields = ("id", "title", "active_from", "questions", "event", "template_type","is_template") class SurveyReadDetailedAdminSerializer(SurveyReadDetailedSerializer): @@ -160,7 +160,7 @@ class SurveyCreateSerializer(BasisModelSerializer): class Meta: model = Survey - fields = ("id", "title", "active_from", "template_type", "event", "questions") + fields = ("id", "title", "active_from", "template_type","is_template", "event", "questions") @atomic def create(self, validated_data): @@ -183,7 +183,7 @@ class SurveyUpdateSerializer(BasisModelSerializer): class Meta: model = Survey - fields = ("id", "title", "active_from", "template_type", "event", "questions") + fields = ("id", "title", "active_from", "template_type","is_template", "event", "questions") @atomic def update(self, instance, validated_data): diff --git a/lego/apps/surveys/views.py b/lego/apps/surveys/views.py index cbeaf08c5..c3c5b427c 100644 --- a/lego/apps/surveys/views.py +++ b/lego/apps/surveys/views.py @@ -151,9 +151,9 @@ class SurveyTemplateViewSet( queryset = ( Survey.objects.all() .prefetch_related("questions") - .filter(template_type__isnull=False) + .filter(is_template__isnull=False) ) - lookup_field = "template_type" + lookup_field = "is_template" filter_backends = (DjangoFilterBackend,) def get_serializer_class(self):