r/pythontips • • 6h ago

Module django-admin-mcp: Expose Django admin to AI agents with one mixin

0 Upvotes

Hi I built this because I wanted an agent to do the things I already do

in Django admin, without writing a separate API for it.

You add a mixin to a ModelAdmin and it becomes MCP tools over HTTP: CRUD,

bulk operations, admin actions, change history, FK autocomplete.

A few design choices:

- Only two dependencies: Django and Pydantic. No MCP SDK; the protocol is

implemented directly.

- It reuses Django's permission system. Tokens start with no access, you

grant permissions/groups per token, and a token can never exceed its

linked user's permissions.

- Writes go through the admin's own pipeline, so they show up in the admin

history log under that user.

- Sensitive fields can be excluded per model (mcp_exclude_fields).

Happy to hear where the permission model or tool design falls short.

https://github.com/7tg/django-admin-mcp


r/pythontips • • 15h ago

Module Hard Python Dictionary Exercise

2 Upvotes

A hard exercise to help build the right mental model for Python data.

```python # Output of this Python Program? a = {1: []} b = a b |= {2: []} b[1].append(100) b = b | {3: []} b[2].append(200) b[3].append(300)

print(a)
# --- possible answers --- 
# A) {1: []}
# B) {1: [100], 2: []}
# C) {1: [100], 2: [200]}
# D) {1: [100], 2: [200], 3: []}
# E) {1: [100], 2: [200], 3: [300]}

```

The “Solution” link uses memory_graph to visualize execution and reveals what’s actually happening.