Reformats report model

This commit is contained in:
Mouse Reeve 2021-03-09 12:57:38 -08:00
parent 999bff4bba
commit 0d2c641d01
2 changed files with 88 additions and 26 deletions

View file

@ -10,41 +10,104 @@ import django.db.models.expressions
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('bookwyrm', '0048_merge_20210308_1754'), ("bookwyrm", "0048_merge_20210308_1754"),
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Report', name="Report",
fields=[ fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), (
('created_date', models.DateTimeField(auto_now_add=True)), "id",
('updated_date', models.DateTimeField(auto_now=True)), models.AutoField(
('remote_id', bookwyrm.models.fields.RemoteIdField(max_length=255, null=True, validators=[bookwyrm.models.fields.validate_remote_id])), auto_created=True,
('note', models.TextField(blank=True, null=True)), primary_key=True,
('resolved', models.BooleanField(default=False)), serialize=False,
('reporter', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='reporter', to=settings.AUTH_USER_MODEL)), verbose_name="ID",
('statuses', models.ManyToManyField(blank=True, null=True, to='bookwyrm.Status')), ),
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), ),
("created_date", models.DateTimeField(auto_now_add=True)),
("updated_date", models.DateTimeField(auto_now=True)),
(
"remote_id",
bookwyrm.models.fields.RemoteIdField(
max_length=255,
null=True,
validators=[bookwyrm.models.fields.validate_remote_id],
),
),
("note", models.TextField(blank=True, null=True)),
("resolved", models.BooleanField(default=False)),
(
"reporter",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="reporter",
to=settings.AUTH_USER_MODEL,
),
),
(
"statuses",
models.ManyToManyField(blank=True, null=True, to="bookwyrm.Status"),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to=settings.AUTH_USER_MODEL,
),
),
], ],
), ),
migrations.CreateModel( migrations.CreateModel(
name='ReportComment', name="ReportComment",
fields=[ fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), (
('created_date', models.DateTimeField(auto_now_add=True)), "id",
('updated_date', models.DateTimeField(auto_now=True)), models.AutoField(
('remote_id', bookwyrm.models.fields.RemoteIdField(max_length=255, null=True, validators=[bookwyrm.models.fields.validate_remote_id])), auto_created=True,
('note', models.TextField()), primary_key=True,
('report', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='bookwyrm.Report')), serialize=False,
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), verbose_name="ID",
),
),
("created_date", models.DateTimeField(auto_now_add=True)),
("updated_date", models.DateTimeField(auto_now=True)),
(
"remote_id",
bookwyrm.models.fields.RemoteIdField(
max_length=255,
null=True,
validators=[bookwyrm.models.fields.validate_remote_id],
),
),
("note", models.TextField()),
(
"report",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="bookwyrm.Report",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to=settings.AUTH_USER_MODEL,
),
),
], ],
options={ options={
'abstract': False, "abstract": False,
}, },
), ),
migrations.AddConstraint( migrations.AddConstraint(
model_name='report', model_name="report",
constraint=models.CheckConstraint(check=models.Q(_negated=True, reporter=django.db.models.expressions.F('user')), name='self_report'), constraint=models.CheckConstraint(
check=models.Q(
_negated=True, reporter=django.db.models.expressions.F("user")
),
name="self_report",
),
), ),
] ]

View file

@ -17,13 +17,12 @@ class Report(BookWyrmModel):
class Meta: class Meta:
""" don't let users report themselves """ """ don't let users report themselves """
constraints = [ constraints = [
models.CheckConstraint( models.CheckConstraint(check=~Q(reporter=F("user")), name="self_report")
check=~Q(reporter=F('user')),
name='self_report'
)
] ]
class ReportComment(BookWyrmModel): class ReportComment(BookWyrmModel):
""" updates on a report """ """ updates on a report """