Skip to content

Commit

Permalink
[Fix] Ordering AWX does not work fields were duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
elias-boulharts committed Dec 18, 2023
1 parent f360771 commit 8e862a6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.6 on 2023-12-18 10:18

from django.db import migrations

def clean_tower_survey_fields(apps, schema_editor):
Operation = apps.get_model("service_catalog", "Operation")
for operation in Operation.objects.all():
if operation.tower_survey_fields.filter(position=0).count() > 1:
operation.tower_survey_fields.exclude(position=0).delete()

class Migration(migrations.Migration):

dependencies = [
('service_catalog', '0039_alter_request_options_alter_request_state_and_more'),
]

operations = [
migrations.RunPython(clean_tower_survey_fields),
migrations.AlterUniqueTogether(
name='towersurveyfield',
unique_together={('operation', 'variable')},
),
migrations.AlterModelOptions(
name='towersurveyfield',
options={'default_permissions': ('add', 'change', 'delete', 'view', 'list'), 'ordering': ('position',)},
),
]
2 changes: 1 addition & 1 deletion service_catalog/models/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def update_survey(self):
for field in spec_list:
squest_field, created = TowerSurveyField.objects.get_or_create(
variable=field['variable'],
position=position,
operation=self,
defaults={
'is_customer_field': True,
'position': position,
'name': field['question_name'],
'description': field['question_description'],
'type': field['type'],
Expand Down
3 changes: 2 additions & 1 deletion service_catalog/models/tower_survey_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def __init__(self, quota=None, *args, **kwargs):

class TowerSurveyField(SquestModel):
class Meta(SquestModel.Meta):
unique_together = ('operation', 'position', 'variable',)
unique_together = ('operation', 'variable')
ordering = ('position',)

variable = CharField(null=False, blank=False, max_length=200)
position = IntegerField(default=0)
Expand Down

0 comments on commit 8e862a6

Please # to comment.