django / django/new-features

Allow for setting Django Admin URL's to use a unique, non-pk field

Open
#118 11 comments 8 reactions 0 assignees View on GitHub
Admin
Dominant language
No language data
Stars
188
Forks
7
PR merge metrics
No merged PRs in 30d

Description

### Code of Conduct

- [x] I agree to follow Django's Code of Conduct

### Feature Description

The goal is to be able to use a non-primary key field in the url while navigating the admin console, such as a unique slug field.

### Problem

Currently when navigating the admin, we may have something like:

mydjangosite.com/admin/myapp/mymodel/**{pk}**/change

Without changing primary key, I would like to be able to access the same page with:

mydjangosite.com/admin/myapp/mymodel/**{slug}**/change

This would make navigating between different environments, such as dev, testing, and production, much easier as I could easily go from:

**dev**-mydjangosite.com/admin/myapp/mymodel/{slug}/change
**uat**-mydjangosite.com/admin/myapp/mymodel/{slug}/change
**prod**-mydjangosite.com/admin/myapp/mymodel/{slug}/change

This would help ensure synced configuration across different environments in the dev cycle.

### Request or proposal

request

### Additional Details

Definitely a low priority but nice-to-have.

As far as I am aware this is not currently possible without overriding some internal django functions to add additional url's. I think the ability to do this would provide a lot of value when navigating between different environments each hosting the same application when syncing between configurations across each environment is important. I've played around a bit with getting this to work (in my case I've hardcoded it to specifically work for slug fields if they exist while still allowing for the pk field to work), and I'm happy to share what I've learned to help make progress on this.

### Implementation Suggestions

I've started with overriding ModelAdmin's `get_object`, `get_urls`, `change_view`, `delete_view`, `history_view` and then also overriding the Changelist `url_for_result`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.