python Django Admin 应用程序还是我自己的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/495879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Django Admin app or roll my own?
提问by Powerlord
I'm just starting to use Django for a personal project.
我刚刚开始将 Django 用于个人项目。
What are the pros and cons of using the built-in Admin application versus integrating my administrative functions into the app itself (by checking request.user.is_staff)?
使用内置管理应用程序与将我的管理功能集成到应用程序本身(通过检查 request.user.is_staff)的优缺点是什么?
This is a community wiki because it could be considered a poll.
这是一个社区维基,因为它可以被视为民意调查。
采纳答案by Koen Bok
It really depends on the project I guess. While you can do everything in the admin, when your app gets more complex using the admin gets more complex too. And if you want to make your app really easy to manage you want control over every little detail, which is not really possible with the admin app.
这真的取决于我猜的项目。虽然您可以在 admin 中完成所有操作,但当您的应用变得更加复杂时,使用 admin 也会变得更加复杂。如果您想让您的应用程序真正易于管理,您需要控制每一个小细节,这在管理应用程序中是不可能的。
I guess you should see it like this:
我想你应该这样看:
Using django admin: save time writing it, lose time using it.
Rolling your own admin: lose time writing it, save time using it.
使用 django admin:节省编写时间,浪费时间。
滚动您自己的管理员:浪费时间编写它,节省使用它的时间。
回答by Ryszard Szopa
I would use Django's admin app, for a number of reasons. First, writing an administration app may be quite tricky and take some time if you want to do it right, and django.contrib.admin
is for free and works out of the box. Second, it is really well designed and very nice to work with (even for non-technical users). Third, it covers a lot of the common cases and it doesn't seem wise to waste time on rewriting it until you are really sure you cannot do otherwise. Fourth, it isn't really so difficult to customize. For example, adding akismet mark-as-spam and mark-as-ham buttons was really a piece of cake.
出于多种原因,我会使用 Django 的管理应用程序。首先,编写管理应用程序可能非常棘手,如果您想正确地完成它需要一些时间,并且django.contrib.admin
是免费的并且开箱即用。其次,它设计得非常好,非常好用(即使对于非技术用户)。第三,它涵盖了很多常见的情况,并且在您确定不能做其他事情之前浪费时间重写它似乎是不明智的。第四,定制并不难。例如,添加 akismet 标记为垃圾邮件和标记为火腿按钮真的是小菜一碟。
回答by Andy Baker
It's so easy to selectively override parts of the admin in varying degrees.
在不同程度上有选择地覆盖部分管理员非常容易。
You can:
你可以:
Override admin templates on an app by app basis or even model by model basis.
Override admin views by inheriting and subclassing
Catch admin url's by putting yours before it in urls.py and provide your own interfaces that are based on admin look and feel
逐个应用程序甚至逐个模型覆盖应用程序上的管理模板。
通过继承和子类化来覆盖管理视图
通过将您的 url 放在 urls.py 中来捕获管理 url,并提供您自己的基于管理外观的界面
...and lots more.
...还有更多。
So start with the admin and then slot in whatever custom functionality you need where you need it.
因此,从管理员开始,然后在需要的地方插入您需要的任何自定义功能。
There are a bunch of apps that do clever things with the admin. For example:
有很多应用程序可以与管理员一起做一些聪明的事情。例如:
- django-reversiontakes over the admin-log and extends it into full history.
- Tusk CMScombines the django-mptt app with JQuery nested sortable widget in a neat way.
- django-reversion接管管理日志并将其扩展到完整的历史记录中。
- Tusk CMS以简洁的方式将 django-mptt 应用程序与 JQuery 嵌套可排序小部件结合在一起。
Also search django-snippets for admin related snippets and this pagehas got a wealth of info.
还可以在 django-snippets 中搜索与管理相关的片段,这个页面有很多信息。
回答by Jim Carroll
Consider using the Django admin, but with your own hand-crafted widgets for particular fields. You can create sophisticated form-parts, and tell the admin to use your code for the inputs and displays of any specific field, or all fields of a type.
考虑使用 Django 管理员,但使用您自己手工制作的特定字段的小部件。您可以创建复杂的表单部件,并告诉管理员将您的代码用于任何特定字段或某个类型的所有字段的输入和显示。
Jannis has done some cool stuff, and his work shows you how easy it is: http://jannisleidel.com/2008/11/wysiwym-editor-widget-django-admin-interface/
Jannis 做了一些很酷的事情,他的工作向你展示了它是多么容易:http: //jannisleidel.com/2008/11/wysiwym-editor-widget-django-admin-interface/
A project that I am working on recently incorporated a time picker that uses drop-downs for the various parts of time, (h, m, s) Another field would indicate which days of the week were recurring... it would use 7 checkboxes for the days of the week, and store that in the database as a pickled dateutil.rruleset. Then, you just give the admin hints on which widgets to use for the various fields.
我最近从事的一个项目包含一个时间选择器,该时间选择器在时间的各个部分使用下拉列表,(h, m, s) 另一个字段将指示一周中的哪几天重复出现......它将使用 7 个复选框对于一周中的几天,并将其作为腌制的 dateutil.rruleset 存储在数据库中。然后,您只需向管理员提供有关用于各个字段的小部件的提示。
It involves defining your data class, your own widget which subclasses forms.Widget, your own Field which subclasses forms.Field, and a model.Field too. Each of the three classes is nice and simple and clean, and is responsible for a transition from the database to the Model, the Model to the Widget, and back through those two steps. It's really a thing of beauty.
它涉及定义你的数据类,你自己的小部件,它是forms.Widget的子类,你自己的Field是forms.Field的子类,还有一个model.Field。这三个类中的每一个都非常好、简单和干净,并且负责从数据库到模型、模型到小部件的转换,然后通过这两个步骤返回。这真的是一件很美的事情。
The fields you create will be some of the most reusable, sophisticated intellectual property that you can accumulate... and you don't have to write your own admin from scratch.
您创建的字段将是您可以积累的一些最可重用、最复杂的知识产权......而且您不必从头开始编写自己的管理员。
回答by hasen
I found sadly, that the while the django admin app saves a lot of time at first, it becomes a hinderence later on, as your costumer demands more features that are not easily integrated with the default admin interface. You might endup with two kinds of admin tools: the django admin (for apps that require simple data entry), and your custom rolled admin interface for other applications that require a richer interface.
我遗憾地发现,虽然 django 管理应用程序一开始节省了大量时间,但后来却成为一个障碍,因为您的客户需要更多不易与默认管理界面集成的功能。您最终可能会使用两种管理工具:django admin(用于需要简单数据输入的应用程序),以及用于需要更丰富界面的其他应用程序的自定义滚动管理界面。
回答by TokenMacGuy
I'd recommend enabling the admin site on just about every type of project. The cost of setting it up is pretty low, and it gives you a reasonably convenient mechanism for inspecting and modifying your site.
我建议在几乎所有类型的项目上启用管理站点。设置它的成本非常低,它为您提供了一种相当方便的机制来检查和修改您的站点。
If your site has mostly a one way flow of information, from webmaster to visitors, then the admin site is probably all you need.
如果您的站点主要是从网站管理员到访问者的单向信息流,那么管理站点可能就是您所需要的。
If, however, your site has a richer interaction among its users, you will need to compose django views that can enable that interaction while also limiting access to what users can really do.
但是,如果您的站点在其用户之间有更丰富的交互,您将需要编写 django 视图来启用该交互,同时还限制对用户真正可以做的事情的访问。
回答by Gromer
I'd go with the Django admin functionality, over writing your own. You can customize the Django admin by adding your own templates for the admin, your own widgets, etc. I'm working on a project with a very customized Django admin. If we had decided to write it by hand, it would have taken 4 times as long to get done. I just can't see a scenario where you would want to write your own.
我会使用 Django 管理功能,而不是自己编写。您可以通过添加您自己的管理模板、您自己的小部件等来自定义 Django 管理。我正在使用一个非常定制的 Django 管理项目。如果我们决定手工编写,则需要 4 倍的时间才能完成。我只是看不到您想要自己编写的场景。