>
>
> I'm -1 on adding it to URLconf and would rather see it in settings.py.
> Perhaps like:
>
> ADMIN_FIND_ADMIN_CLASSES = True
> ADMIN_MODELS = (
> 'myproj.myapp.admin.PollAdmin',
> 'someotherproj.someapp.admin.FooAdmin',
> )
>
> Where ADMIN_FIND_ADMIN_CLASSES (or whatever we want to call it)
> permits autodiscovery of the ModelAdmin classes in the app/admin.py
> files. The ADMIN_MODELS settings are explicit ModelAdmins that would
> override anything autodiscovered or mbe the only ModelAdmins if
> ADMIN_FIND_ADMIN_CLASSES = False.
I'm -1 on introducing any new settings.
> pps. I'm +1 on the inner Admin class explicitly subclassing ModelAdmin
> as opposed to the current magic.
This got me thinking, if the inner admin is going to stay then there is
going to be a meta.admin attribute. So we could just override the ModelAdmin
in the Meta class. I have a copy of the newforms-admin branch checked out
and it is really easy to allow this to work and does not require any extra
code at all. Well except for:
line 13 in django.db.models.options
DEFAULT_NAMES add 'admin'
Now I can define a ModelAdmin in my models.py or anywhere else and it works
as expected.
from django.contrib.admin.options import ModelAdmin
class MyModelAdmin(ModelAdmin):
#define your options
list_display = ('name','email')
class Test(models.Model):
name = CharField(maxlength=20)
email = EmailField()
class Meta:
admin = MyModelAdmin
And your done. I know it is not sexy but it works and is very easy to
comprehend, without messing with the urlconf logic. Now I present version 2.
Make the inner class extend meta.admin if it exists. This allows you to
write a generic ModelAdmin class that extends ModelAdmin but still allow the
inner class to override any option. So I could make a ModelAdmin class that
overrides the default has_add_permission() method and apply it to every
model while still defining the options in the inner class. This requires two
lines in django.db.models.base:
line 133 in django.db.models.base
from django.contrib.admin.options import ModelAdmin
if cls._meta.admin:
ModelAdmin = cls._meta.admin
Now my model can extend MyModelAdmin class and define a list_filter
class Test(models.Model):
name = CharField(maxlength=20)
email = EmailField()
class Meta:
admin = MyModelAdmin
class Admin:
list_filter = ('name',)
And you get the list_display defined in MyModelAdmin and the list_filter in
the inner admin class. Which I think a little more DRY than overriding
everysingle model with a separate ModelAdmin. Especially if you only want to
change the default behavior of one thing in the ModelAdmin class. Also if
you do not define either the inner Admin class or the Meta.admin option the
model will not show in the admin list as expected.
Robert
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---