I'm new to Django and I have a question working with ManyToManyFields in Django with Admin.
So I have two model classes.
class Tag(models.Model):
tag = models.CharField(max_length=100)
def __str__(self):
return self.tag
class Meta:
ordering = ['tag']
verbose_name = "tag"
verbose_name_plural = "tags"
class MyiPhoneApp(models.Model):
tags = models.ManyToManyField(Tag)
name = models.CharField(max_length=200)
bundleID = models.CharField(max_length=200, primary_key=True)
def __str__(self):
return self.name
class Meta:
ordering = ['name']
verbose_name = "iPhone App"
verbose_name_plural = "iPhone Apps"
So when I register this classes to Admin I can add some iPhone Apps. But after adding one App with 2 tags and saving, there is happing something strange when I'm adding a second app or more.
every App has every tag attribute.
I thought that a many to many field is the right relationship to represent this.
One App has many Tags and One Tag has Many Apps
But now every App has every available tag from db assigned and this behaviour is wrong :/
Is my relationship wrong or have I forget something to add to my (model)code?