class Pet(models.Model): name = models.CharField(max_length=50) tags = TaggableManager() def __str__(self): return self.name
class BlankTagModel(models.Model): name = models.CharField(max_length=50) tags = TaggableManager(blank=True) def __str__(self): return self.name
class OfficialPet(models.Model): name = models.CharField(max_length=50) tags = TaggableManager(through=OfficialThroughModel) def __str__(self): return self.name
class CustomPKPet(models.Model): name = models.CharField(max_length=50, primary_key=True) tags = TaggableManager(through=TaggedCustomPK) def __str__(self): return self.name
class DirectTrackedPet(models.Model): name = models.CharField(max_length=50) tags = TaggableManager(through=TaggedTrackedPet) def __str__(self): return self.name
class DirectFood(models.Model): name = models.CharField(max_length=50) tags = TaggableManager(through="TaggedFood") def __str__(self): return self.name
class UUIDPet(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) name = models.CharField(max_length=50) tags = TaggableManager(through="UUIDTaggedItem") created_at = models.DateTimeField(auto_now_add=True) def __str__(self): return self.name class Meta: # With a UUIDField pk, objects are not always ordered by creation time. So explicitly set ordering. ordering = ["created_at"]
class Tag(models.Model): name = models.CharField(unique=True, max_length=100) slug = models.SlugField(unique=True, max_length=100) objects = ExtendedManager() tags = TaggableManager() def __str__(self): return f"{self.name}" def save(self, *args, **kwargs): self.slug = slugify(self.name) super().save(*args, **kwargs)
class MultiInheritanceFood(BaseFood): tags = TaggableManager(through=MultiInheritanceLazyResolutionFoodTag) def __str__(self): return self.name
class Name(models.Model): tags = TaggableManager(related_name="a_unique_related_name")
class MultipleTagsGFK(models.Model): tags1 = TaggableManager(related_name="tagsgfk1") tags2 = TaggableManager(through=ThroughGFK, related_name="tagsgfk2")
class Parent(models.Model): tags = TaggableManager()
class CustomManager(models.Model): class Foo: def __init__(*args, **kwargs): pass tags = TaggableManager(manager=Foo)
class Article(models.Model): title = models.CharField(max_length=100) tags = TaggableManager(through=ArticleTaggedItem)
class Media(models.Model): tags = TaggableManager() class Meta: abstract = True
class MutipleTags(models.Model): tags1 = TaggableManager(through=Through1, related_name="tags1") tags2 = TaggableManager(through=Through2, related_name="tags2")