Reputation: 519
I have TbPeopleEntranceRights that is referencing TbUser TbRoom and TbArea. TbArea has multiple TbRooms. I wnat to get TbAreas and TbRooms that are not referenced by TbPeopleEntranceRights having a specific user. So I will get the rooms to the user for rooms for which user does not have permission yet.
I need this when having and user and all entrance rights. All rooms and areas.
class TbArea(models.Model):
id = models.CharField(primary_key=True, max_length=40)
area_name = models.CharField(max_length=60, blank=True, null=True)
class TbRoom(models.Model):
id = models.CharField(primary_key=True, max_length=40)
room_name = models.CharField(max_length=60, blank=True, null=True)
area = models.ForeignKey(
TbArea, on_delete=models.CASCADE, db_column='room_area_id')
class TbPeopleEntranceRight(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
area = models.ForeignKey(
TbArea, on_delete=models.CASCADE, db_column='room_area_id')
room = models.ForeignKey(
TbRoom, on_delete=models.CASCADE, db_column='room_id')
user = models.ForeignKey(
TbUser, on_delete=models.CASCADE, db_column='people_id')
last_update_time = models.BigIntegerField(blank=True, null=True)
class TbUser(AbstractBaseUser, PermissionsMixin):
id = models.CharField(primary_key=True, max_length=32, default=uuid.uuid4)
username = models.CharField(
max_length=40, blank=True, null=True, unique=True, db_column='usname')
password = models.CharField(
max_length=255, blank=True, null=True, db_column='psword')
Upvotes: 1
Views: 361
Reputation: 7330
If you want to get TbArea objects which are not referenced by TbPeopleEntranceRights(for the logged in user)then you can do like this.
TbArea.objects.filter(tbpeopleentranceright__isnull=True, tbpeopleentranceright__user=request.user)
Upvotes: 1