1👍
✅
Since your labels are static and pre-defined:
TAGS = ((1,'DOG'),(2,'CAT'),(3,'HORSE')) # and so on
class MyThing(models.Model):
name = models.CharField(max_length=200)
tag = models.IntegerField(choices=TAGS)
With this model, your thing can only have one tag, and you can get the associated tag for your object thus:
foo = MyThing.objects.order_by('?')[0] # get some random object
print 'My object is a ',foo.get_tag_display()
0👍
What about a simple model with some relations ?
class LabeledItem(models.Model):
my_object= models.OneToOneField(Item)
label = models.CharField()
The label property could also be a OneToOneField to for example a Label model which has a name as field property.
- [Answer]-How to change DateField format representation
- [Answer]-Apply tinyMCE settings to dynamicly created textarea
Source:stackexchange.com