moviewyrm/bookwyrm/models/group.py
Hugh Rundle 686198472d update group and list models
- remove GroupList model
- add a group foreign key value  to List model
- remove reference to lists in Group model
2021-09-26 15:50:15 +10:00

38 lines
No EOL
1 KiB
Python

""" 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()
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)
user = models.ForeignKey("User", on_delete=models.CASCADE)
class Meta:
constraints = [
models.UniqueConstraint(
fields=["group", "user"], name="unique_member"
)
]