kopia lustrzana https://gitlab.com/marnanel/chapeau
ForeignKey of Status back to Person renamed "poster"
Statuses can't be replies to, or reblogs of, themselves.trilby-heavy
rodzic
0b99864320
commit
fff3bd00d2
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 3.0.4 on 2020-04-15 16:58
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trilby_api', '0004_auto_20200415_1506'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='status',
|
||||
name='account',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='poster', to='trilby_api.Person'),
|
||||
),
|
||||
]
|
|
@ -28,6 +28,7 @@ class Status(models.Model):
|
|||
|
||||
account = models.ForeignKey(
|
||||
'Person',
|
||||
related_name = 'poster',
|
||||
on_delete = models.DO_NOTHING,
|
||||
)
|
||||
|
||||
|
@ -201,3 +202,13 @@ class Status(models.Model):
|
|||
current = child
|
||||
|
||||
return result
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
||||
if self.reblog_of == self:
|
||||
raise ValueError("Status can't be a reblog of itself")
|
||||
|
||||
if self.in_reply_to == self:
|
||||
raise ValueError("Status can't be a reply to itself")
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
|
Ładowanie…
Reference in New Issue