I'm trying to get a count of the number of Users that are connected to a Room. A User can be connected to only one Room, a Room can have many Users.
My models look like this
class User(AbstractBaseUser, PermissionsMixin):
"""Database model for users"""
screen_name = models.CharField(max_length=255, unique=True)
room = models.ForeignKey(
Room, related_name='room', on_delete=models.CASCADE
)
...
class Room(models.Model):
"""Database model for rooms"""
name = models.CharField(max_length=100)
is_full = models.BooleanField(default=False)
...
What I'm trying to do is lock any instance of a Room out once a certain number of Users have been assigned to it. How do I go about finding the number of Users connected to a given room? Pseudo code of what I'm trying.
my_room.users.count >= max_users:
my_room.is_full = True
Thank you in advance.