From b74cd3709629f52c7c0dce1a321888fd7c7b21d1 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Fri, 24 Sep 2021 07:49:54 +1000 Subject: [PATCH] add models for groups --- bookwyrm/models/__init__.py | 2 ++ bookwyrm/models/group.py | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 bookwyrm/models/group.py diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py index bffd62b45..2774f081d 100644 --- a/bookwyrm/models/__init__.py +++ b/bookwyrm/models/__init__.py @@ -21,6 +21,8 @@ from .relationship import UserFollows, UserFollowRequest, UserBlocks from .report import Report, ReportComment from .federated_server import FederatedServer +from .group import Group, GroupList, GroupMember + from .import_job import ImportJob, ImportItem from .site import SiteSettings, SiteInvite diff --git a/bookwyrm/models/group.py b/bookwyrm/models/group.py new file mode 100644 index 000000000..a91c56cb1 --- /dev/null +++ b/bookwyrm/models/group.py @@ -0,0 +1,45 @@ +""" do book related things with other users """ +from django.apps import apps +from django.db import models +from django.utils import timezone + +from bookwyrm.settings import DOMAIN +from .base_model import BookWyrmModel +from . import fields + + +class Group(BookWyrmModel): + """A group of users""" + + name = fields.CharField(max_length=100) + manager = fields.ForeignKey( + "User", on_delete=models.PROTECT) + description = fields.TextField(blank=True, null=True) + privacy = fields.PrivacyField() + + lists = models.ManyToManyField( + "List", + symmetrical=False, + through="GroupList", + through_fields=("group", "book_list"), + ) + + members = models.ManyToManyField( + "User", + symmetrical=False, + through="GroupMember", + through_fields=("group", "user"), + related_name="members" + ) + +class GroupList(BookWyrmModel): + """Lists that group members can edit""" + + group = models.ForeignKey("Group", on_delete=models.CASCADE) + book_list = models.ForeignKey("List", on_delete=models.CASCADE) + +class GroupMember(models.Model): + """Users who are members of a group""" + + group = models.ForeignKey("Group", on_delete=models.CASCADE) + user = models.ForeignKey("User", on_delete=models.CASCADE) \ No newline at end of file