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.

Custom API key model w/o default `APIKey` table or admin

See original GitHub issue

I would like to be able to inherit AbstractAPIKey directly from the model, without having to reference it via foreignkey, and also I would like django, to not create these tables at all:

class APIKey(AbstractAPIKey):
    pass

I would like to: Inherit the Abstract class, without having to reference the model.

I would solve it by: Not installing the app at all, if we migrated the code of the abstract base class away from models.py, we would be able to inherit without problems.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
stpddreamcommented, Nov 22, 2021

I have a similar need here. Would like to

  • have my own CustomizedAPIKey that extends AbstractApiKey
  • I don’t need the default APIKey model and would like to remove the table from db & admin options as it will be very confusing.

Not installing the app causes a similar error as discussion above: RuntimeError: Model class rest_framework_api_key.models.APIKey doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

Is there a way to do that?

Thanks!

1reaction
florimondmancacommented, Dec 5, 2021

I think we’d also want to remove the admin.site.register(APIKey, APIKeyModelAdmin) call in rest_framework_api_key/admin.py, and have users explicitly register the default APIKey if they’d like. It could be done as a first step so users don’t see APIKey if they don’t want to, but also if we decide to have a swappable API_KEY_MODEL setting, that’d be required as otherwise we’d be registering a model from a different app, which isn’t desirable (and could lead to conflicts).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authenticate using API keys - Google Cloud
This page describes how to use API keys to authenticate to Google Cloud APIs and services that support API keys. Most Google Cloud...
Read more >
User Guide - Django REST Framework API Key - GitHub Pages
The APIKey model as well as custom API keys models inherited from AbstractAPIKey have a dedicated manager which is responsible for implementing .create_key() ......
Read more >
Use API Keys | Maps JavaScript API - Google Developers
Create API keys​​ The API key is a unique identifier that authenticates requests associated with your project for usage and billing purposes. You...
Read more >
API keys | Grafana documentation
This section contains information about API keys in Grafana. ... Admin: Enables a user to use APIs at the broadest, most powerful administrative...
Read more >
Issues · florimondmanca/djangorestframework-api-key - GitHub
API key permissions for Django REST Framework. ... Import not working ... Custom API key model w/o default APIKey table or admin question...
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