I cant decide which way is better to create a key/value Tag model in Django,
class Tag(models.Model):
tag = models.CharField(max_length=35, unique=True)
description = models.CharField(max_length=250, null=True)
is_key = models.BooleanField(default=False)
parent = models.ForeignKey("self", blank=True, related_name="key")
or
class TagKey(models.Model):
key = models.CharField(max_length=35, unique=True)
description = models.CharField(max_length=250, null=True)
class TagValue(models.Model):
value = models.CharField(max_length=35, unique=True)
description = models.CharField(max_length=250, null=True)
port = models.PositiveIntegerField(default=0)
key = models.ForeignKey(TagKey)
All I intent to do is create a key:value based tag model which I can use to tag my applications.
Explanation: What I am doing in Tag class is that I am giving a self relation to itself when I will be adding a value tag, but if I am adding a key type Tag then I wont be populating the parent field.
P.S I have to use my own tag model so please don't suggest third party Django tag app
Aucun commentaire:
Enregistrer un commentaire