1from django.contrib.contenttypes.fields import GenericForeignKey
2from django.contrib.contenttypes.models import ContentType
3from django.db import models
4
5class TaggedItem(models.Model):
6 tag = models.SlugField()
7 content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
8 object_id = models.PositiveIntegerField()
9 content_object = GenericForeignKey('content_type', 'object_id')
10
11 def __str__(self):
12 return self.tag
13
1ctype = ContentType.objects.get(model='user')
2related_to_user = Room.objects.filter(content_type=ctype)