Add user model field for followers url

This commit is contained in:
Mouse Reeve 2021-08-28 10:33:57 -07:00
parent f308b7793d
commit e9d951e4cd
2 changed files with 29 additions and 4 deletions

View file

@ -0,0 +1,26 @@
# Generated by Django 3.2.4 on 2021-08-28 17:24
import bookwyrm.models.fields
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookwyrm', '0085_user_saved_lists'),
]
operations = [
migrations.AddField(
model_name='user',
name='followers_url',
field=bookwyrm.models.fields.CharField(default='/followers', max_length=255),
preserve_default=False,
),
migrations.AlterField(
model_name='user',
name='followers',
field=models.ManyToManyField(through='bookwyrm.UserFollows', to=settings.AUTH_USER_MODEL),
),
]

View file

@ -82,13 +82,12 @@ class User(OrderedCollectionPageMixin, AbstractUser):
preview_image = models.ImageField(
upload_to="previews/avatars/", blank=True, null=True
)
followers = fields.ManyToManyField(
followers_url = fields.CharField(max_length=255, activitypub_field="followers")
followers = models.ManyToManyField(
"self",
link_only=True,
symmetrical=False,
through="UserFollows",
through_fields=("user_object", "user_subject"),
related_name="following",
)
follow_requests = models.ManyToManyField(
"self",
@ -228,7 +227,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
def to_followers_activity(self, **kwargs):
"""activitypub followers list"""
remote_id = "%s/followers" % self.remote_id
remote_id = self.followers_url
return self.to_ordered_collection(
self.followers.order_by("-updated_date").all(),
remote_id=remote_id,