Created
April 15, 2020 04:16
-
-
Save daimon99/6822dcfcdce579e48f53c5a62f0dc227 to your computer and use it in GitHub Desktop.
Django admin 的新增和修改页面使用不同的字段 / Different fields for add and change pages in django admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_fields(self, request, obj=None): | |
if not obj: | |
# 新增页面的字段 | |
fields = ['name', 'company', 'project'] | |
else: | |
# 修改页面的字段 | |
fields = super().get_fields(request, obj) | |
return fields |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment