Skip to content

Commit a7b5b40

Browse files
committed
Remove and replace multiple choice with choice field
1 parent 6b53fdf commit a7b5b40

File tree

11 files changed

+30
-19
lines changed

11 files changed

+30
-19
lines changed

app/tests/custom_fields/test_custom_field_base_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def test_custom_field_base_manager_annotate_multiple_date_choice_value(
147147
content_type=self.person_ct,
148148
field_type=CustomField.FIELD_TYPES.DATE,
149149
choice_field=True,
150-
multiple_choice=True,
150+
multiple=True,
151151
)
152152
choice_1 = CustomValueFactory(
153153
field=field, text_de="Choice 1", value="2000-01-01"

app/tests/custom_fields/test_custom_field_base_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def test_custom_field_base_model_set_multiple_choice_value(
275275
content_type=self.person_ct,
276276
field_type=CustomField.FIELD_TYPES.DATE,
277277
choice_field=True,
278-
multiple_choice=True,
278+
multiple=True,
279279
)
280280
choice_1 = CustomValueFactory(field=field, value="2000-01-01")
281281
choice_2 = CustomValueFactory(field=field, value="2001-01-01")

app/tests/custom_fields/test_custom_field_model_base_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def setUp(self) -> None:
6969
content_type=self.person_ct,
7070
field_type=CustomField.FIELD_TYPES.DATE,
7171
choice_field=True,
72-
multiple_choice=True,
72+
multiple=True,
7373
)
7474
self.choice_1 = CustomValueFactory(field=self.choice_field, value="2000-01-01")
7575
self.choice_2 = CustomValueFactory(field=self.choice_field, value="2001-01-01")

app/tests/custom_fields/test_custom_field_serializer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def test_custom_base_field_serializer(self) -> None:
3131
"label": "Custom Field Label",
3232
"modified": ANY,
3333
"multiple": False,
34-
"multiple_choice": False,
3534
"order": 0,
3635
},
3736
data,
@@ -90,7 +89,6 @@ def test_custom_choice_field_serializer(self) -> None:
9089
"label": "Custom Field Label",
9190
"modified": ANY,
9291
"multiple": False,
93-
"multiple_choice": False,
9492
"order": 0,
9593
},
9694
data,

app/tests/test_mapping_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def setUp(self) -> None:
8989
content_type=self.person_ct,
9090
field_type=CustomField.FIELD_TYPES.DATE,
9191
choice_field=True,
92-
multiple_choice=True,
92+
multiple=True,
9393
)
9494

9595
self.choice_1 = CustomValueFactory(field=self.choice_field, value="2000-01-01")

django_features/custom_fields/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_queryset(self) -> CustomValueQuerySet:
3838
def to_representation(
3939
self, value: CustomValue | CustomValueQuerySet
4040
) -> int | list[int]:
41-
return CustomChoiceSerializer(value, many=self.field.multiple_choice).data
41+
return CustomChoiceSerializer(value, many=self.field.multiple).data
4242

4343
def _choice_field(self, data: int | str | dict) -> CustomValue:
4444
if isinstance(data, dict):
@@ -66,7 +66,7 @@ def _multiple_choice(self, data: list[int | str | dict]) -> CustomValueQuerySet:
6666
return values
6767

6868
def to_internal_value(self, data: Any) -> CustomValue | CustomValueQuerySet:
69-
if self.field.multiple_choice and isinstance(data, list):
69+
if self.field.multiple and isinstance(data, list):
7070
return self._multiple_choice(data)
7171
elif self.field.choice_field and isinstance(data, (int, str, dict)):
7272
return self._choice_field(data)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 4.2.23 on 2025-10-22 11:59
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("custom_fields", "0003_add_type_filter_to_fields"),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name="customfield",
15+
name="multiple_choice",
16+
),
17+
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0003_add_type_filter_to_fields
1+
0004_remove_mutiple_choice_field

django_features/custom_fields/models/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _subquery(self, field: CustomField) -> Subquery:
6565
).values_list("formated", flat=True)
6666
)
6767
else:
68-
sq = ArraySubquery if field.multiple_choice else Subquery
68+
sq = ArraySubquery if field.multiple else Subquery
6969
return sq(
7070
custom_values_queryset.annotate(
7171
formated=JSONObject(id="id", text="text", value="value")
@@ -161,7 +161,7 @@ def _create_or_update_custom_value(self, field: str, value: Any) -> None:
161161

162162
def _set_choice_value(self, field: CustomField, value: Any) -> None:
163163
self._custom_values_to_remove.extend(CustomValue.objects.filter(field=field))
164-
if field.multiple_choice:
164+
if field.multiple:
165165
# We expect a list for multiple choice fields, so we must extend the list with the items of the list
166166
self._custom_values_to_save.extend(value)
167167
else:

django_features/custom_fields/models/field.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ class CustomField(TimeStampedModel):
9393
identifier = models.SlugField(max_length=64, unique=True, db_index=True)
9494
label = models.CharField(verbose_name=_("Name"))
9595
multiple = models.BooleanField(verbose_name=_("Liste"), default=False)
96-
multiple_choice = models.BooleanField(
97-
verbose_name=_("Mehrfachauswahlfeld"), default=False
98-
)
9996
order = models.PositiveSmallIntegerField(verbose_name=_("Reihenfolge"), default=0)
10097
required = models.BooleanField(verbose_name=_("Erforderlich"), default=False)
10198

0 commit comments

Comments
 (0)