I have the following model:
class Channel(models.Model):
tags = models.ManyToManyField(Tag)
class Tag(models.Model):
name = models.CharField( primary_key = True)
And want to get_or_create
a channel that has exactly the given set of tags.
tags = map(lambda x: Tag.objects.get(name = x), ['tag1', 'tag2'])
channel = Channel.objects.get_or_create(tags = tags) # Here's the bug
Edit: looks like the problem is with the create
part, because
Channel.objects.get(tags=tags)
works just fine. So it is the usual problem with saving a many-many relationship.