Querying many to many fields in django

Posted by Hulk on Stack Overflow See other posts from Stack Overflow or by Hulk
Published on 2010-04-01T11:09:32Z Indexed on 2010/04/01 11:13 UTC
Read the original article Hit count: 575

In the models there is a many to many fields as,

from emp.models import Name

  def info(request):
     name = models.ManyToManyField(Name)

And in emp.models the schema is as

 class Name(models.Model):
      name = models.CharField(max_length=512)


      def __unicode__(self):
          return self.name

Now when i want to query a particular id say for ex:

         info=  info.objects.filter(id=a)
         for i in info:
              logging.debug(i.name) //gives an error 

how should the query be to get the name

Thanks..

© Stack Overflow or respective owner

Related posts about django

Related posts about django-views