Tolto tema di default con Django e warning brutto
parent
a96cede14f
commit
9272e6563b
|
|
@ -10,8 +10,8 @@ def get_active_theme(request):
|
||||||
obj = objs_manager.first()
|
obj = objs_manager.first()
|
||||||
if obj:
|
if obj:
|
||||||
obj.set_active()
|
obj.set_active()
|
||||||
else:
|
# else:
|
||||||
obj = objs_manager.create()
|
# obj = objs_manager.create()
|
||||||
|
|
||||||
elif objs_active_count == 1:
|
elif objs_active_count == 1:
|
||||||
obj = objs_active_ls[0]
|
obj = objs_active_ls[0]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Generated by Django 4.0.3 on 2022-10-25 13:59
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
from django.db import transaction, connection
|
||||||
|
|
||||||
|
def forward(apps, schema_editor):
|
||||||
|
Theme = apps.get_model("admin_interface", "Theme")
|
||||||
|
if len(Theme.objects.all()) == 1 and Theme.objects.first().name == 'Django':
|
||||||
|
with transaction.atomic():
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute("""truncate table "admin_interface_theme" restart identity;""")
|
||||||
|
|
||||||
|
def reverse(apps, schema_editor):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('admin_interface', '0028_alter_theme_demo'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(forward, reverse),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='usertheme',
|
||||||
|
name='user',
|
||||||
|
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -20,8 +20,8 @@ class UserTheme(models.Model):
|
||||||
verbose_name = 'Users theme'
|
verbose_name = 'Users theme'
|
||||||
verbose_name_plural = 'Users themes'
|
verbose_name_plural = 'Users themes'
|
||||||
|
|
||||||
user = models.ForeignKey(
|
user = models.OneToOneField(
|
||||||
'auth.User', on_delete=models.CASCADE, null=True, unique=True)
|
'auth.User', on_delete=models.CASCADE, null=True)
|
||||||
theme = models.ForeignKey('Theme', on_delete=models.CASCADE)
|
theme = models.ForeignKey('Theme', on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -65,8 +65,8 @@ class Theme(models.Model):
|
||||||
obj = objs_manager.all().first()
|
obj = objs_manager.all().first()
|
||||||
if obj:
|
if obj:
|
||||||
obj.set_active()
|
obj.set_active()
|
||||||
else:
|
# else:
|
||||||
obj = objs_manager.create()
|
# obj = objs_manager.create()
|
||||||
|
|
||||||
elif objs_active_count == 1:
|
elif objs_active_count == 1:
|
||||||
obj = objs_active_ls[0]
|
obj = objs_active_ls[0]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue