Skip to content

Commit

Permalink
docs: how to register existing models
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasvinclav committed Jan 10, 2023
1 parent 7e7921f commit 9823e9e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ urlpatterns = [
After installation, it is required that admin classes are going to inherit from custom `ModelAdmin` available in `unfold.admin`.

```python
# admin.py

from django.contrib import admin
from unfold.admin import ModelAdmin

Expand All @@ -83,6 +85,25 @@ class CustomAdminClass(ModelAdmin):
pass
```

**Note:** Registered admin models coming from third party packages are not going to properly work with Unfold because of parent class. By default, these models are registered by using `django.contrib.admin.ModelAdmin` but it is needed to use `unfold.admin.ModelAdmin`. Solution for this problem is to unregister model and then again register it back by using `unfold.admin.ModelAdmin`.

```python
# admin.opy
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.models import User

from unfold.admin import ModelAdmin


admin.site.unregister(User)


@admin.register(User)
class UserAdmin(BaseUserAdmin, ModelAdmin):
pass
```

## Configuration

### Available settings.py options
Expand Down

0 comments on commit 9823e9e

Please sign in to comment.