mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-03-16 22:20:28 +00:00
Add uniqueness setting and optionally connect signal
This commit is contained in:
parent
43a038ec2d
commit
5af2a26f97
4 changed files with 31 additions and 0 deletions
|
|
@ -1,4 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
from django.conf import settings
|
||||
from django.db.models.signals import m2m_changed
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
|
|
@ -7,3 +9,10 @@ class DBTemplatesConfig(AppConfig):
|
|||
verbose_name = _('Database templates')
|
||||
|
||||
default_auto_field = 'django.db.models.AutoField'
|
||||
|
||||
def ready(self):
|
||||
from .models import Template
|
||||
from .signal_handlers import verify_template_name_uniqueness_across_all_selected_sites
|
||||
|
||||
if getattr(settings, 'DBTEMPLATES_UNIQUE', False):
|
||||
m2m_changed.connect(verify_template_name_uniqueness_across_all_selected_sites, sender=Template.sites.through)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class DbTemplatesConf(AppConf):
|
|||
AUTO_POPULATE_CONTENT = True
|
||||
MEDIA_PREFIX = None
|
||||
CACHE_BACKEND = None
|
||||
UNIQUE = False
|
||||
|
||||
def configure_media_prefix(self, value):
|
||||
if value is None:
|
||||
|
|
|
|||
18
dbtemplates/migrations/0003_template_template_name_idx.py
Normal file
18
dbtemplates/migrations/0003_template_template_name_idx.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 5.1 on 2025-05-26 19:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dbtemplates', '0002_alter_template_creation_date_and_more'),
|
||||
('sites', '0002_alter_domain_unique'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddIndex(
|
||||
model_name='template',
|
||||
index=models.Index(fields=['name'], name='template_name_idx'),
|
||||
),
|
||||
]
|
||||
|
|
@ -36,6 +36,9 @@ class AbstractTemplateMixin(models.Model):
|
|||
verbose_name = _('template')
|
||||
verbose_name_plural = _('templates')
|
||||
ordering = ('name',)
|
||||
indexes = [
|
||||
models.Index(fields=["name"], name="template_name_idx"),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
|
|||
Loading…
Reference in a new issue