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.

Admin Model Not Integrating into Django Admin Page

See original GitHub issue

Went to add this app to my project and noticed it wasn’t automatically added to my Django admin page. I tried manually adding it in my admin.py and it appeared:

from rest_framework_api_key.admin import APIKeyAdmin
from rest_framework_api_key.models import APIKey

admin.site.register(APIKey, APIKeyAdmin)

However, when I navigated to Home/API Key Permissions/API Keys I received the following error:

AttributeError at /admin/rest_framework_api_key/apikey/ Unable to lookup 'has_expired_func' on APIKey or APIKeyAdmin

My temporary fix was to create a new admin model by subclassing the one given by this app:

from rest_framework_api_key.admin import APIKeyAdmin
from rest_framework_api_key.models import APIKey

class BaseAPIKeyAdmin(APIKeyAdmin):

    list_display = (
        "name",
        "prefix",
        "created",
        "expiry_date",
        "revoked",
    )

admin.site.register(APIKey, BaseAPIKeyAdmin)

Thereby removing has_expired_func from list_display.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ScottHullcommented, Jun 3, 2019

Excellent, thank you for following up with this in such a timely manner! Unfortunately I’m a bit busy to attempt a PR at the moment, but I’ll keep it in mind if I get a moment.

My temporary fix that I listed in the first comment is working well for my project, especially since I made many custom modifications in the form of subclassing your models.

1reaction
ScottHullcommented, Jun 3, 2019

Sure thing. Worth noting that I verified that this package was installed correctly (i.e. in INSTALLED_APPS) and that I had run the migrations.

Python==3.5.6 Django==2.1.5 djangorestframework==3.7.7

Edit: typo

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django admin page not showing user models - Stack Overflow
Regisrar your models in admin.py file. from . models import Model_Name. Then you can register your models in two ways: I) ...
Read more >
custom model not showing up in django admin - YouTube
custom model not showing up in django admin | admin.sites.register(MyModel) doesn't work [ Solved ]. 2,215 views ...
Read more >
Django Tutorial Part 4: Django admin site - MDN Web Docs
First we'll show you how to register the models with the admin site, then we'll show you how to login and create some...
Read more >
The Django admin site
One of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick,...
Read more >
Django admin integration
Although the child models are registered too, they won't be shown in the admin index page. This only happens when show_in_index is set...
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