Skip to content

Commit

Permalink
feat: update localized unique normalized slug field to use lazy gener…
Browse files Browse the repository at this point in the history
…ator
  • Loading branch information
huynguyengl99 committed Jun 4, 2024
1 parent 9cf53fc commit 6759f27
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 81 deletions.
6 changes: 6 additions & 0 deletions headless_cms/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from reversion.models import Version
from solo.admin import SingletonModelAdmin

from headless_cms.fields import LocalizedUniqueNormalizedSlugField
from headless_cms.models import (
LocalizedPublicationModel,
LocalizedSingletonModel,
Expand Down Expand Up @@ -517,9 +518,13 @@ def auto_admins(
admin_attrs = {"history_latest_first": True}
inlines = []
exclude = []
readonly_fields = []
model_fields = model._meta.get_fields()
has_sortable_base = False
for field in model_fields:
if isinstance(field, LocalizedUniqueNormalizedSlugField):
readonly_fields.append(field.name)

if isinstance(field, ManyToManyField) and issubclass(
field.related_model, LocalizedPublicationModel
):
Expand Down Expand Up @@ -549,6 +554,7 @@ def auto_admins(

admin_attrs["inlines"] = inlines
admin_attrs["exclude"] = exclude
admin_attrs["readonly_fields"] = readonly_fields

base_admin = []
if has_sortable_base:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.11 on 2024-05-22 15:03
# Generated by Django 4.2.13 on 2024-06-04 18:00

import django.db.models.deletion
import localized_fields.fields.char_field
Expand All @@ -21,7 +21,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand Down Expand Up @@ -56,7 +56,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand Down Expand Up @@ -101,7 +101,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand Down Expand Up @@ -130,7 +130,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand Down Expand Up @@ -183,7 +183,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -201,10 +201,7 @@ class Migration(migrations.Migration):
localized_fields.fields.text_field.LocalizedTextField(
blank=True,
default=dict,
help_text=(
"Title template (default should be %s - {title}), used for"
" default site metadata."
),
help_text="Title template (default should be %s - {title}), used for default site metadata.",
null=True,
required=[],
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.11 on 2024-05-22 15:03
# Generated by Django 4.2.13 on 2024-06-04 18:00

import django.db.models.deletion
import localized_fields.fields.char_field
Expand All @@ -21,7 +21,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -40,7 +40,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -59,7 +59,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -83,7 +83,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -102,7 +102,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -126,7 +126,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -150,7 +150,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -169,7 +169,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand Down Expand Up @@ -259,7 +259,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -283,7 +283,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.11 on 2024-05-22 15:03
# Generated by Django 4.2.13 on 2024-06-04 18:00

import django.db.models.deletion
from django.db import migrations, models
Expand All @@ -9,9 +9,9 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
("astrowind_pages", "0001_initial"),
("astrowind_widgets", "0001_initial"),
("reversion", "0002_add_index_on_version_for_content_type_and_db"),
("astrowind_pages", "0001_initial"),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.11 on 2024-05-22 15:03
# Generated by Django 4.2.13 on 2024-06-04 18:00

import django.db.models.deletion
import localized_fields.fields.char_field
Expand Down Expand Up @@ -26,7 +26,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -47,7 +47,7 @@ class Migration(migrations.Migration):
null=True,
populate_from="title",
required=[],
uniqueness=["en", "vi", "zh", "ar"],
uniqueness=headless_cms.fields.slug_field.Uniqueness,
),
),
(
Expand All @@ -70,7 +70,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -91,7 +91,7 @@ class Migration(migrations.Migration):
null=True,
populate_from="title",
required=[],
uniqueness=["en", "vi", "zh", "ar"],
uniqueness=headless_cms.fields.slug_field.Uniqueness,
),
),
(
Expand Down Expand Up @@ -142,7 +142,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand Down Expand Up @@ -177,7 +177,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -198,7 +198,7 @@ class Migration(migrations.Migration):
null=True,
populate_from="title",
required=[],
uniqueness=["en", "vi", "zh", "ar"],
uniqueness=headless_cms.fields.slug_field.Uniqueness,
),
),
(
Expand All @@ -221,7 +221,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.BigAutoField(
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand Down
Loading

0 comments on commit 6759f27

Please sign in to comment.