Skip to content

Make AbstractAPIToken user field a ForeignKey - #7

Merged
domdinicola merged 1 commit into
mainfrom
feature/make-token-user-foreignkey
Aug 31, 2026
Merged

Make AbstractAPIToken user field a ForeignKey#7
domdinicola merged 1 commit into
mainfrom
feature/make-token-user-foreignkey

Conversation

@domdinicola

Copy link
Copy Markdown
Contributor

Summary

Overrides DRF's Token.user OneToOneField in AbstractAPIToken to be a ForeignKey, allowing a user to have multiple API tokens.

Changes

  • src/hope_api_auth/models.py: override user as ForeignKey(AUTH_USER_MODEL) with related_name="api_tokens".
  • src/hope_api_auth/migrations/0001_initial.py: updated user field from OneToOneField to ForeignKey to reflect the existing DB schema (plain non-unique user_id FK), so no new migration is needed — verified by makemigrations --check --dry-run.

Verification

  • ruff passes
  • makemigrations --check --dry-run hope_api_auth reports no changes
  • Full test suite: 53 passed, 2 skipped

@domdinicola
domdinicola merged commit 785af4d into main Aug 31, 2026
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants