Skip to content

Commit

Permalink
[#1524] Started with making ContactFormSubject model an ordered one
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed Jun 20, 2023
1 parent 8c950d2 commit 187a6d1
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/open_inwoner/openklant/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from ordered_model.admin import OrderedTabularInline
from solo.admin import SingletonModelAdmin

from .models import ContactFormSubject, OpenKlantConfig


class ContactFormSubjectInlineAdmin(admin.TabularInline):
class ContactFormSubjectInlineAdmin(OrderedTabularInline):
model = ContactFormSubject
fields = [
"move_up_down_links",
"subject",
]
readonly_fields = ("move_up_down_links",)
ordering = ("order",)
extra = 0


Expand Down
26 changes: 26 additions & 0 deletions src/open_inwoner/openklant/migrations/0004_auto_20230620_1419.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 3.2.15 on 2023-06-20 12:19

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("openklant", "0003_auto_20230526_1013"),
]

operations = [
migrations.AlterModelOptions(
name="contactformsubject",
options={
"verbose_name": "Contact formulier onderwerp",
"verbose_name_plural": "Contact formulier onderwerpen",
},
),
migrations.AddField(
model_name="contactformsubject",
name="order",
field=models.PositiveIntegerField(
db_index=True, default=0, editable=False, verbose_name="order"
),
),
]
22 changes: 22 additions & 0 deletions src/open_inwoner/openklant/migrations/0005_auto_20230620_1419.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.15 on 2023-06-20 12:19

from django.db import migrations


def populate_order_of_subjects(apps, schema_editor):
Subject = apps.get_model("openklant", "ContactFormSubject")
for subject in Subject.objects.all():
subject.order = subject.pk
subject.save()


class Migration(migrations.Migration):
dependencies = [
("openklant", "0004_auto_20230620_1419"),
]

operations = [
migrations.RunPython(
populate_order_of_subjects, reverse_code=migrations.RunPython.noop
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.15 on 2023-06-20 14:34

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("openklant", "0005_auto_20230620_1419"),
]

operations = [
migrations.AlterField(
model_name="contactformsubject",
name="order",
field=models.PositiveIntegerField(
db_index=True, editable=False, verbose_name="order"
),
),
]
7 changes: 5 additions & 2 deletions src/open_inwoner/openklant/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _

from ordered_model.models import OrderedModel, OrderedModelManager
from solo.models import SingletonModel
from zgw_consumers.constants import APITypes

Expand Down Expand Up @@ -86,7 +87,7 @@ def has_api_configuration(self):
return all(getattr(self, f, "") for f in self.register_api_required_fields)


class ContactFormSubject(models.Model):
class ContactFormSubject(OrderedModel):
subject = models.CharField(
verbose_name=_("Onderwerp"),
max_length=255,
Expand All @@ -97,10 +98,12 @@ class ContactFormSubject(models.Model):
on_delete=models.CASCADE,
)

order_with_respect_to = "subject"
objects = OrderedModelManager()

class Meta:
verbose_name = _("Contact formulier onderwerp")
verbose_name_plural = _("Contact formulier onderwerpen")
ordering = ("subject",)

def __str__(self):
return self.subject

0 comments on commit 187a6d1

Please sign in to comment.