Adds deactivation date to user model

Also fixes django admin around saved lists
This commit is contained in:
Mouse Reeve 2021-09-11 08:57:38 -07:00
parent 84b90db4bb
commit 430554444f
2 changed files with 41 additions and 1 deletions

View file

@ -0,0 +1,39 @@
# Generated by Django 3.2.4 on 2021-09-11 15:50
from django.db import migrations, models
from django.db.models import F, Value, CharField
def set_deactivate_date(apps, schema_editor):
"""best-guess for deactivation date"""
db_alias = schema_editor.connection.alias
apps.get_model("bookwyrm", "User").objects.using(db_alias).filter(
is_active=False
).update(deactivation_date=models.F("last_active_date"))
def reverse_func(apps, schema_editor):
"""noop"""
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0093_alter_sitesettings_instance_short_description"),
]
operations = [
migrations.AddField(
model_name="user",
name="deactivation_date",
field=models.DateTimeField(blank=True, null=True),
),
migrations.AlterField(
model_name="user",
name="saved_lists",
field=models.ManyToManyField(
blank=True, related_name="saved_lists", to="bookwyrm.List"
),
),
migrations.RunPython(set_deactivate_date, reverse_func),
]

View file

@ -105,7 +105,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
related_name="blocked_by",
)
saved_lists = models.ManyToManyField(
"List", symmetrical=False, related_name="saved_lists"
"List", symmetrical=False, related_name="saved_lists", blank=True
)
favorites = models.ManyToManyField(
"Status",
@ -136,6 +136,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
deactivation_reason = models.CharField(
max_length=255, choices=DeactivationReason.choices, null=True, blank=True
)
deactivation_date = models.DateTimeField(null=True, blank=True)
confirmation_code = models.CharField(max_length=32, default=new_access_code)
name_field = "username"