2021-09-23 21:49:54 +00:00
|
|
|
""" 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)
|
2021-09-27 05:36:41 +00:00
|
|
|
user = fields.ForeignKey(
|
2021-09-23 21:49:54 +00:00
|
|
|
"User", on_delete=models.PROTECT)
|
|
|
|
description = fields.TextField(blank=True, null=True)
|
|
|
|
privacy = fields.PrivacyField()
|
|
|
|
members = models.ManyToManyField(
|
|
|
|
"User",
|
|
|
|
symmetrical=False,
|
|
|
|
through="GroupMember",
|
|
|
|
through_fields=("group", "user"),
|
|
|
|
related_name="members"
|
|
|
|
)
|
|
|
|
|
|
|
|
class GroupMember(models.Model):
|
|
|
|
"""Users who are members of a group"""
|
|
|
|
|
|
|
|
group = models.ForeignKey("Group", on_delete=models.CASCADE)
|
2021-09-25 07:34:44 +00:00
|
|
|
user = models.ForeignKey("User", on_delete=models.CASCADE)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
constraints = [
|
|
|
|
models.UniqueConstraint(
|
|
|
|
fields=["group", "user"], name="unique_member"
|
|
|
|
)
|
|
|
|
]
|