forked from mirrors/bookwyrm
parent
efd93855d9
commit
27b9326dd9
3 changed files with 59 additions and 0 deletions
39
fedireads/migrations/0002_auto_20200219_0725.py
Normal file
39
fedireads/migrations/0002_auto_20200219_0725.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Generated by Django 3.0.3 on 2020-02-19 07:25
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('fedireads', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Favorite',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('content', models.TextField(blank=True, null=True)),
|
||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
||||
('relationship_id', models.CharField(max_length=100)),
|
||||
('status', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='fedireads.Status')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='status',
|
||||
name='favorites',
|
||||
field=models.ManyToManyField(related_name='user_favorites', through='fedireads.Favorite', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='favorites',
|
||||
field=models.ManyToManyField(related_name='favorite_statuses', through='fedireads.Favorite', to='fedireads.Status'),
|
||||
),
|
||||
]
|
|
@ -16,6 +16,13 @@ class Status(FedireadsModel):
|
|||
local = models.BooleanField(default=True)
|
||||
privacy = models.CharField(max_length=255, default='public')
|
||||
sensitive = models.BooleanField(default=False)
|
||||
favorites = models.ManyToManyField(
|
||||
'User',
|
||||
symmetrical=False,
|
||||
through='Favorite',
|
||||
through_fields=('status', 'user'),
|
||||
related_name='user_favorites'
|
||||
)
|
||||
reply_parent = models.ForeignKey(
|
||||
'self',
|
||||
null=True,
|
||||
|
@ -38,3 +45,9 @@ class Review(Status):
|
|||
self.activity_type = 'Article'
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class Favorite(FedireadsModel):
|
||||
''' fav'ing a post '''
|
||||
user = models.ForeignKey('User', on_delete=models.PROTECT)
|
||||
status = models.ForeignKey('Status', on_delete=models.PROTECT)
|
||||
relationship_id = models.CharField(max_length=100)
|
||||
|
|
|
@ -40,6 +40,13 @@ class User(AbstractUser):
|
|||
through='UserRelationship',
|
||||
through_fields=('user_subject', 'user_object')
|
||||
)
|
||||
favorites = models.ManyToManyField(
|
||||
'Status',
|
||||
symmetrical=False,
|
||||
through='Favorite',
|
||||
through_fields=('user', 'status'),
|
||||
related_name='favorite_statuses'
|
||||
)
|
||||
|
||||
@property
|
||||
def absolute_id(self):
|
||||
|
|
Loading…
Reference in a new issue