Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensions to @admin.register fixer #190

Closed
adamchainz opened this issue Sep 12, 2022 · 5 comments
Closed

Extensions to @admin.register fixer #190

adamchainz opened this issue Sep 12, 2022 · 5 comments

Comments

@adamchainz
Copy link
Owner

adamchainz commented Sep 12, 2022

Description

Following #182 / #189 , there are a few more cases that could be covered with further work.

  1. Support kwarg form ✅ Support admin_class as keyword argument in @admin.register fixer #192
+@admin.register(MyModel)
 class MyModelAdmin(...):
    ...

-admin.site.register(MyModel, admin_class=MyModelAdmin)
  1. Support multiple models ✅ Support multiple model classes in @admin.register fixer #200
+@admin.register(Model1, Model2)
 class MyModelAdmin(...):
    ...

-admin.site.register(Model1, MyModelAdmin)
-admin.site.register(Model2, MyModelAdmin)
+@admin.register(Model1, Model2)
 class MyModelAdmin(...):
    ...

-admin.site.register((Model1, Model2), MyModelAdmin)
  1. Support when there are other class decorators, insert at top ✅ Support stacking class decorator in @admin.register fixer #193
+@admin.register(MyModel)
 @something
 class MyModelAdmin(...):
    ...

-admin.site.register(MyModel, MyModelAdmin)
  1. Support custom admin sites ✅ Support custom admin classes in @admin.register fixer #228
from myapp.admin import custom_site

+@admin.register(MyModel, site=custom_site)
 class MyModelAdmin(...):
    ...

-custom_site.register(MyModel, MyModelAdmin)
  • detect custom site objects heuristically, to avoid affecting other code that uses a 'register' pattern, perhaps when the object's name ends in 'site', and the registered class name ends in 'Admin' (and maybe the file looks like an admin file, called "admin.py" or in an "admin" directory?)
  1. Also work for from django.contrib.gis import admin - ✅ Support admin import from gis in @admin.register fixer #204
    This imports the register decorator for convenience when authoring GIS apps.
@adamchainz
Copy link
Owner Author

@UnknownPlatypus I have entertained myself tackling the two easiest ones here, perhaps you'd like to try the other two?

@UnknownPlatypus
Copy link
Contributor

@adamchainz Absolutely, would be nice to work on that and I think I have some ideas on how to tackle them.

@adamchainz
Copy link
Owner Author

@UnknownPlatypus added point 5 above as well, for GIS admins.

@adamchainz
Copy link
Owner Author

Alright we've checked everything off from this list! 🥳

This is now a really awesome feature that covers many cases. Great work @UnknownPlatypus .

@UnknownPlatypus
Copy link
Contributor

Thank again @adamchainz for the continuous support along the way and the kind help with my first few contributions to the open source community. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants