2

Possible Duplicate:
Django get a model's fields

I have next model:

class People(models.Model):
    name = models.CharField(max_length=100)
    lastname = models.CharField(max_length=100)

I want to loop through all items from People table.

In views.py

-When I try this one:

  for each in People().objects.all():
     name=each.name

I am getting that error:

Manager isn't accessible via People instances

-When I try this one:

  for each in People():
     name=each.name

I am getting this error:

'People' object is not iterable

How can I fix that and how to loop through all items from my People table ?

Community
  • 1
  • 1
John Smith
  • 2,668
  • 7
  • 30
  • 34

1 Answers1

8

People.objects.all()

it works on the class not an instance People not People()

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179