How to get object id inside views.py applications on django?

For example:

there is person = Person.objects.all () and ptrson.id does not issue.

  • 2
    If you use Person.objects.all (), then the appropriate name for the variable is persons (pl. H.). Such a name already in the course of writing persons.id will make you think: which ID of the personnel you want to receive. - idle sign

1 answer 1

Person.objects.all () - selection of all objects of the Person model. The id of the first object in the list can be obtained as follows:

Person.objects.all()[0].id