How to show __str__ representations for existing Inline objects in the admin UI, but still use the form for adding new objects huangapple 117266文章 0评论 2023年4月19日 21:47:46go评论75阅读模式 英文: How to show __str__ representations for existing Inline objects in the admin UI, but still use the form for adding new objects 问题 我有一个Django管理员视图,其中有许多嵌套视图。"添加另一个"按预期工作,并显示一个空表单以填入值。 但一旦添加,它会在表单视图中显示相关的对象,并且所有嵌套视图上的字段仍然可编辑。 我想实现的是,所有现有对象都以它们的__str__表示形式列出,但"添加另一个"按钮仍然会显示表单。 这在Django管理员中可行吗,还是我期望过高? 英文: I have a Django Admin view with a number of inlines. The 'Add another <object>' works as expected and brings up an empty form to fill in the values. Once added though, it shows that related object in form view, and all fields on all inlines remain editable. What I'd like to achieve is that all existing objects are listed in their __str__ representation, but the 'Add another' button still brings up the form. Can this be done in Django Admin, or am I looking for too much? 答案1 得分: 1 Django确实支持这个功能。这个功能是通过ModelAdmin.has_change_permission方法提供的。您可以像这样使用它: class FoobarModelInline(admin.TabularInline): model = Foobar def has_change_permission(self, request, obj=None): return False 您可能还对has_delete_permission方法感兴趣。 英文: Django does indeed support this. This functionality is provided by the ModelAdmin.has_change_permission method. You would use it like this: class FoobarModelInline(admin.TabularInline): model = Foobar def has_change_permission(self, request, obj=None): return False You might also be interested in the has_delete_permission method. 通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。 点赞 https://go.coder-hub.com/76055314.html 复制链接 复制链接 本文由 huangapple 发表于 2023年4月19日 21:47:46 转载请务必保留本文链接:https://go.coder-hub.com/76055314.html django django-admin 如何修复自动添加正斜杠 go 88 02/18 连接Snowflake在Django中使用代理 go 105 06/06 Import (cannot import name 'ResolveInfo' from 'graphql') error when using newest graphene and graphene-django version go 170 01/04 Django身份验证表单未正常工作。 go 97 06/25 如何在Playwright视觉比较中屏蔽多个定位器? 在C++中,可以使用可变模板参数来检索类型的内部类型。 selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: stale element not found Creating and opening a URL to log in to Website via Basic Auth with Robot Framework/Selenium (Python) AG Grid 在上下文菜单中以大文本形式打开 What's the correct way to type hint an empty list as a literal in python? 如何在Highcharts Gantt中更改本地化的星期名称 如何在同一个流中使用多个过滤器和映射函数? 如何使用Map/Set来将代码优化到O(n)? .NET MAUI Android在GitHub Actions上构建失败,错误代码为1。 如何在Playwright视觉比较中屏蔽多个定位器? 在C++中,可以使用可变模板参数来检索类型的内部类型。 selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: stale element not found Creating and opening a URL to log in to Website via Basic Auth with Robot Framework/Selenium (Python) AG Grid 在上下文菜单中以大文本形式打开 What's the correct way to type hint an empty list as a literal in python? 如何在Highcharts Gantt中更改本地化的星期名称 如何在同一个流中使用多个过滤器和映射函数? 如何使用Map/Set来将代码优化到O(n)? .NET MAUI Android在GitHub Actions上构建失败,错误代码为1。 发表评论 匿名网友 # 确定 昵称 邮箱 网址 Address 取消
Import (cannot import name 'ResolveInfo' from 'graphql') error when using newest graphene and graphene-django version go 170 01/04
评论