views:

46

answers:

1

In my django views i have the following

def create(request):

  query=header.objects.filter(id=a)[0]
  a=query.criteria_set.all()
  logging.debug(a.details)

I get an error saying 'QuerySet' object has no attribute 'details' in the debug statement .What is this error and what should be the correct statemnt to query this.And the model corresponding to this is as follows

where as the models has the following:

class header(models.Model):
   title = models.CharField(max_length = 255)
   created_by = models.CharField(max_length = 255)

   def __unicode__(self):
     return self.id()

 class criteria(models.Model):
    details =   models.CharField(max_length = 255)
    headerid = models.ForeignKey(header)

    def __unicode__(self):
      return self.id()

Thanks..

+3  A: 

QuerySet.all() returns a QuerySet. Index it or iterate over it if you want to access the individual models:

logging.debug(a[0].details)

for m in a:
  logging.debug(m.details)
Ignacio Vazquez-Abrams
Thanks..............
Hulk