Question

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..

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top