mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-03-16 22:20:24 +00:00
57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
|
|
# Import your custom models
|
|
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
|
|
from django.contrib.auth.models import Group, User
|
|
|
|
from rest_framework.relations import PrimaryKeyRelatedField
|
|
|
|
import djadmin2
|
|
from djadmin2.forms import floppify_form
|
|
from djadmin2.apiviews import Admin2APISerializer
|
|
|
|
from .models import Post, Comment
|
|
|
|
|
|
UserCreationForm = floppify_form(UserCreationForm)
|
|
UserChangeForm = floppify_form(UserChangeForm)
|
|
|
|
|
|
class GroupSerializer(Admin2APISerializer):
|
|
permissions = PrimaryKeyRelatedField(many=True)
|
|
|
|
class Meta:
|
|
model = Group
|
|
|
|
|
|
class GroupAdmin2(djadmin2.ModelAdmin2):
|
|
api_serializer_class = GroupSerializer
|
|
|
|
|
|
class UserSerializer(Admin2APISerializer):
|
|
user_permissions = PrimaryKeyRelatedField(many=True)
|
|
|
|
class Meta:
|
|
model = User
|
|
exclude = ('passwords',)
|
|
|
|
|
|
class CommentInline(djadmin2.Admin2Inline):
|
|
model = Comment
|
|
|
|
|
|
class PostAdmin(djadmin2.ModelAdmin2):
|
|
inlines = [CommentInline]
|
|
|
|
|
|
class UserAdmin2(djadmin2.ModelAdmin2):
|
|
create_form_class = UserCreationForm
|
|
update_form_class = UserChangeForm
|
|
|
|
api_serializer_class = UserSerializer
|
|
|
|
|
|
# Register each model with the admin
|
|
djadmin2.default.register(Post, PostAdmin)
|
|
djadmin2.default.register(Comment)
|
|
djadmin2.default.register(User, UserAdmin2)
|
|
djadmin2.default.register(Group, GroupAdmin2)
|