mardi 4 août 2015

django ManyToMany realtionship doesn't work

I'm trying to do this in my models.py:

class Tag(models.Model):
    ''' snip '''
    name = models.CharField(max_length=30)

class Stuff(models.Model):
    kind = models.CharField(max_length=30)
    tag = models.ManyToManyField(Tag)

But when i make qury from Stuff in shell the relationship fields return 'None' like this:

>>> q = Stuff.objects.all()
>>> p = q.tag.name
>>> print q.tag.name
None

I can't use this keys in my template too. Data base backend is mysql.

What is the problem?

Aucun commentaire:

Enregistrer un commentaire