Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

301
Visualizações
Django - Change Fields in Group Admin Model

The built-in django group model on the admin site only shows name:

enter image description here

but I want to include additional fields that are already part of the group model, such as id.

I have tried adding these fields using the following admin.py setup:

from django.contrib import admin
from django.contrib.auth.models import Group


class GroupsAdmin(admin.ModelAdmin):
    list_display = ["name", "pk"]
    class Meta:
        model = Group

admin.site.register(Group, GroupsAdmin)

But this returns the error:

django.contrib.admin.sites.AlreadyRegistered: The model Group is already registered.

I have successfully registered other models (I've created) on admin but the above doesn't work for those models that are already a part of django.

How can I add fields in the admin model for Group?

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The accepted answer is correct, however, I would like to point out that you could inherit from the GroupAdmin, if your goal is only extending that is and not modifying:

from django.contrib.auth.admin import GroupAdmin

class GroupsAdmin(GroupAdmin):
    list_display = ["name", "pk"]

admin.site.unregister(Group)
admin.site.register(Group,GroupsAdmin)
about 4 years ago · Santiago Trujillo Relatório

0

You need to unregister it first from the built-in Group model and then register it again with your custom GroupAdmin model.

So:

class GroupsAdmin(admin.ModelAdmin):
    list_display = ["name", "pk"]
    class Meta:
        model = Group

admin.site.unregister(Group)
admin.site.register(Group, GroupsAdmin)

Also, the Meta class is not required. You can remove it.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda