linkding/bookmarks/migrations/0007_userprofile.py

67 lines
1.9 KiB
Python
Raw Normal View History

2021-03-28 10:11:56 +00:00
# Generated by Django 2.2.18 on 2021-03-26 22:39
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
def forwards(apps, schema_editor):
2024-01-27 10:29:16 +00:00
User = apps.get_model("auth", "User")
UserProfile = apps.get_model("bookmarks", "UserProfile")
2021-03-28 10:11:56 +00:00
for user in User.objects.all():
try:
if user.profile:
continue
except UserProfile.DoesNotExist:
profile = UserProfile(user=user)
profile.save()
def reverse(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
2024-01-27 10:29:16 +00:00
("bookmarks", "0006_bookmark_is_archived"),
2021-03-28 10:11:56 +00:00
]
operations = [
migrations.CreateModel(
2024-01-27 10:29:16 +00:00
name="UserProfile",
2021-03-28 10:11:56 +00:00
fields=[
2024-01-27 10:29:16 +00:00
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"theme",
models.CharField(
choices=[
("auto", "Auto"),
("light", "Light"),
("dark", "Dark"),
],
default="auto",
max_length=10,
),
),
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="profile",
to=settings.AUTH_USER_MODEL,
),
),
2021-03-28 10:11:56 +00:00
],
),
migrations.RunPython(forwards, reverse),
]