Last active
September 5, 2019 04:30
-
-
Save daimon99/2061514448c31cc30f3371a99d473ad8 to your computer and use it in GitHub Desktop.
django默认显示只读页面,点击编辑之后再进入编辑页面
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
@admin.register(m.Article) | |
class ArticleAdmin(admin.ModelAdmin): | |
def get_readonly_fields(self, request, obj=None): | |
if 'edit' in request.GET or '/add/' == request.path[-5:]: | |
return self.readonly_fields | |
else: | |
return self.get_fields(request, obj) |
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
{% extends "admin/change_form.html" %} | |
{% load i18n admin_urls static admin_modify %} | |
{% block object-tools-items %} | |
{% if not request.GET.edit %} | |
<li><a href="?edit=1">修改</a></li> | |
{% endif %} | |
{{ block.super }} | |
{% endblock %} | |
{% if save_on_top %}{% block submit_buttons_top %}{% if add or request.GET.edit %}{% submit_row %}{% endif %}{% endblock %}{% endif %} | |
{% block submit_buttons_bottom %} | |
{% if add or request.GET.edit %}{% submit_row %}{% endif %} | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
效果演示: