Задать вопрос

Тел: +7 965 3737 888

462

Просмотров

2

Ответов

Type less with newforms admin

<p>I recently converted a site with over 60 models to newforms admin.  I
like the seperation of the display from the defintion, but it does
introduce quite a bit more typing which isn't in the spirit of Django
DRY...</p>
<p>I particular I got bored of typing</p>
admin.site.register(Model, ModelAdmin)

<p>Over and over again so I wrote this little bit of code which does a
bit of introspection.  It assumes that</p>
<ol><li>You import all your models into your admin.py, ie from "myapp.models import *"</li>
<li>The admin class for Model is called ModelAdmin</li>
</ol><p>Put this snippet at the end of your admin.py</p>
<p>I hope that saves someone a bit of typing!</p>

Вопрос полезен? Да0/Нет0
file_5185.py(209.0б)
None

Ответы (2):

Ответjho406:30.07.2008
Ответ полезен? Да0/Нет0

@aarond10ster

Your referring to old-forms admin. Django 1.0 alpha uses newforms-admin and has completely decoupled admin from the models.

Ответaarond10ster:27.07.2008
Ответ полезен? Да0/Нет0

Ummm...

class MyModel:
    ...
    class Admin:
         pass

Is this too hard to do? It does involve an extra 20 characters per model but gives you freedom to customise as needed later on and explicitly states whats going on.