What is doing __str__ function in Django?

前端 未结 6 2436
猫巷女王i
猫巷女王i 2021-02-13 13:09

I\'m reading and trying to understand django documentation so I have a logical question.

There is my models.py file

from django.db import mo         


        
6条回答
  •  天命终不由人
    2021-02-13 13:50

    The __str__ method just tells Django what to print when it needs to print out an instance of the any model. It is also what lets your admin panel, go from this

    Note: how objects are just plainly numbered

    to this

    .

    Note: proper object names here

    You could choose what to show in the admin panel, as per your choice. Be it a field value or a default value or something else.

提交回复
热议问题