I have a category kind of model (called Tag):
class Tag(models.Model):
name = models.CharField(...)
slug = models.SlugField(unique=True)
#...
Used as m2m field in another model:
class Order(models.Model):
user = models.ForeignKey(...)
type = models.CharField(...)
tag = models.ManyToManyField(Tag, blank=True)
Now, suppose an order is created and program wants to assign some tags to it automatically. Say, program wants to add Order.type
to itsOrder.tag
list. (Suppose Order.type
happens to be same as a valid Tag.name
)
I tried Order's post_save
to no luck:
def order_post_save_reciever(sender, instance, *args, **kwargs):
#..., disconnect, ...
instance.tag.add(Tag.objects.filter(name=instance.type))
instance.save()
#.... reconnec, t.....
Apparently, I have to use signals, but I don't know how. Do you know how to add a tag here? Your help is much appreciated.