开发者

django admin foreignKey display troubles

开发者 https://www.devze.com 2023-01-02 21:12 出处:网络
I can\'t seem to find a solution for the following in the django docs. So for example, i have a field in Class table called department that points to De开发者_运维问答partment database (foreignKey).

I can't seem to find a solution for the following in the django docs.

So for example, i have a field in Class table called department that points to De开发者_运维问答partment database (foreignKey). If I create a admin interface for Class table called ClassAdmin(admin.ModelAdmin). Then i create an entry for Department class. Now automatically, when i try to create a new Class entry, it will show a dropdown menu for entries in Department. The problem arises when i try to do that, it would show something along the lines of "Department Object" for each entry in the dropdown. I would like a way to define canonical names for each entry for department (Department.name is the field i would like to use).

Does anyone know how to do that?

Thanks a lot!


Implement the __str__ method in your Department model:

def __str__(self):
    return self.name
0

精彩评论

暂无评论...
验证码 换一张
取 消