mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-01 11:19:32 -05:00
Apply suggestions from code review
This commit is contained in:
parent
65bc65ac02
commit
7756d49e5c
@ -15,8 +15,9 @@ def migrate_customfield_selects(apps, schema_editor):
|
||||
CustomField = apps.get_model("documents", "CustomField")
|
||||
|
||||
with transaction.atomic():
|
||||
for custom_field in CustomField.objects.all():
|
||||
if custom_field.data_type == "select": # CustomField.FieldDataType.SELECT
|
||||
for custom_field in CustomField.objects.filter(
|
||||
data_type="select",
|
||||
): # CustomField.FieldDataType.SELECT
|
||||
old_select_options = custom_field.extra_data["select_options"]
|
||||
custom_field.extra_data["select_options"] = [
|
||||
{"id": get_random_string(16), "label": value}
|
||||
@ -26,9 +27,9 @@ def migrate_customfield_selects(apps, schema_editor):
|
||||
|
||||
for instance in CustomFieldInstance.objects.filter(field=custom_field):
|
||||
if instance.value_select:
|
||||
instance.value_select = custom_field.extra_data[
|
||||
"select_options"
|
||||
][int(instance.value_select)]["id"]
|
||||
instance.value_select = custom_field.extra_data["select_options"][
|
||||
int(instance.value_select)
|
||||
]["id"]
|
||||
instance.save()
|
||||
|
||||
|
||||
|
@ -552,7 +552,7 @@ class CustomFieldSerializer(serializers.ModelSerializer):
|
||||
)
|
||||
# labels are valid, generate ids if not present
|
||||
for option in attrs["extra_data"]["select_options"]:
|
||||
if "id" not in option or option["id"] is None:
|
||||
if option.get("id") is None:
|
||||
option["id"] = get_random_string(length=16)
|
||||
elif (
|
||||
"data_type" in attrs
|
||||
|
Loading…
x
Reference in New Issue
Block a user