question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extensions to `@admin.register` fixer

See original GitHub issue

Description

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

  1. Support kwarg form ✅ #192
+@admin.register(MyModel)
 class MyModelAdmin(...):
    ...

-admin.site.register(MyModel, admin_class=MyModelAdmin)
  1. Support multiple models ✅ #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 ✅ #193
+@admin.register(MyModel)
 @something
 class MyModelAdmin(...):
    ...

-admin.site.register(MyModel, MyModelAdmin)
  1. Support custom admin sites ✅ #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 - ✅ #204 This imports the register decorator for convenience when authoring GIS apps.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
adamchainzcommented, Sep 21, 2022

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

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

1reaction
UnknownPlatypuscommented, Sep 13, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Admin & Management - Chrome Web Store
Discover great apps, games, extensions and themes for Google Chrome.
Read more >
Cannot Enable or Disable Microsoft Edge Extensions [Tutorial]
Your Admin Has Blocked Extension - Cannot Enable or Disable Microsoft Edge Extensions [Tutorial]If you are unable to enable or disable Edge ...
Read more >
Works! Fix Chrome (or Edge) is Managed by your ...
How to fix Chrome or Edge is Managed by your Organization in 3 easy steps. ... It can also randomly disable or prevent...
Read more >
Google Chrome → Chrome Extension Blocked By Admin? Try ...
Go to https://chrome.google.com/ and find the extension you want to use. In this case we will be use uBlocker as an example.
Read more >
Alternative extension installation methods - Chrome Developers
How to install Chrome Extensions via preferences JSON or Windows registry.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found