added Mention class

issue-47
Marnanel Thurman 2020-10-29 04:14:04 +00:00
rodzic c797fdaf74
commit 53e157dc6a
3 zmienionych plików z 62 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,26 @@
# Generated by Django 3.0.9 on 2020-10-29 03:26
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('trilby_api', '0027_localperson_gone'),
]
operations = [
migrations.CreateModel(
name='Mention',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('status', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='trilby_api.Status')),
('whom', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='trilby_api.Person')),
],
),
migrations.AddConstraint(
model_name='mention',
constraint=models.UniqueConstraint(fields=('status', 'whom'), name='mention_unique'),
),
]

Wyświetl plik

@ -3,6 +3,7 @@ from .status import *
from .notification import *
from .like import *
from .follow import *
from .mention import *
__all__ = [
'TrilbyUser',
@ -13,4 +14,5 @@ __all__ = [
'Notification',
'Like',
'Follow',
'Mention',
]

Wyświetl plik

@ -0,0 +1,34 @@
# mention.py
#
# Part of kepi.
# Copyright (c) 2018-2020 Marnanel Thurman.
# Licensed under the GNU Public License v2.
import logging
logger = logging.getLogger(name='kepi')
from django.db import models
from django.db.models.constraints import UniqueConstraint
class Mention(models.Model):
status = models.ForeignKey(
'Status',
on_delete = models.DO_NOTHING,
)
whom = models.ForeignKey(
'Person',
on_delete = models.DO_NOTHING,
)
class Meta:
constraints = [
UniqueConstraint(
fields = ['status', 'whom'],
name = 'mention_unique',
),
]
def __str__(self):
return '[%s mentions %s]' % (self.status, self.whom)