Django admin page Removing 'Group' - django

How do I delete the model groups admin page? I want to show that by default, the group model. Thank you very much in advance.

Use the unregister method :
Add to the admin.py file :
from django.contrib import admin
from django.contrib.auth.models import Group
admin.site.unregister(Group)

You need to check the order of INSTALLED_APPS in settings.py. Basically, your app should be listed after the django.contrib.auth.
Use the following code to unregister the Group inside admin.py file of your app:
from django.contrib.auth.models import User
admin.site.unregister(Group)

Related

Issue in adding sub-apps in settings.py file

I am unable to add my sub apps like category, user in settings.py. It was working fine but don't know what mistake I have done. Please help. I'm not able to progress from here.
Please create a model and get that model to admin panel.
Link to github
in the admin.py within your "api" folder register the created models so as to display it in the admin panel,
api: admin.py
from django.contrib import admin
from .models import (model created in the models.py)
# Register your models here.
admin.site.register(model created in the models.py)
link to official documentation :
Admin site Official docs

Unable to register the default user model with django.contrib.admin

I'm trying to manage my User table with django.contrib.admin
But during I add the User table in admin, I had an issue that doesn't appear in admin site.
Here is my code.
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
#admin.register(User)
class CustomUserAdmin(UserAdmin):
pass
assert admin.site.is_registered(User) # Fails here
And when I added the other custom model, it works.
Thanks
When you modify or implement the user model, you have to be aware of AUTH_USER_MODEL.
I changed AUTH_USER_MODEL in setting.py, and it starts to work.
Thanks.

Django-Oscar un-registering a class from admin panel

I would like to un-register a ModelAdmin class from the default oscar app.
I created an admin.py file and did the following but was unable to obtain the desired result.
from django.contrib import admin
from oscar.apps.address.admin import *
admin.site.unregister(UserAddressAdmin)
admin.site.unregister(CountryAdmin)
The model is still displayed in the admin panel.
I want the model to be created but I do not want to display the same in the admin panel.
Any help would be greatly appreciated. Thanks.
admin.site.unregister takes the Model class that you want to unregister - you are passing it a ModelAdmin class, which it will just ignore. This should work:
from oscar.core.loading import get_model
admin.site.unregister(get_model('address', 'useraddress'))
admin.site.unregister(get_model('address', 'country'))
However this is all unnecessary! Why don't you just put an empty admin.py file in your fork of the app? Currently you are importing Oscar's admin registrations only to manually unregister all of them again. Just don't import them.

Django import-export buttons DO NOT appear in admin screen

I followed the django import-export manual but the Import Export buttons do not appear in my admin screen.
This is what I have in my admin.py. Is there anything else I need to do? I have added import-export to my settings.py.
from django.contrib import admin
from costtool import models as m
from costtool.models import UserProfile, Prices
from import_export import resources
from import_export.admin import ImportExportModelAdmin, ImportMixin
class PriceResource(resources.ModelResource):
class Meta:
model = Prices
class PriceAdmin(ImportExportModelAdmin):
resource_class = PriceResource
pass
admin.site.register(UserProfile)
admin.site.register(Prices)
Just tell the admin what ModelAdmin to use:
admin.site.register(Prices, PriceAdmin)
You can check Django's ModelAdmin doc and try to use the new register decorator if you're using Django 1.7

How do I customize Django's Flatpage to display a new field on the change list page of the admin?

In my flatpage admin change list page, mysite.com/admin/flatpages/flatpage/, I can see the fields:
URL
Title
Is there a way to also show the field Site? I associate my flatpages to specific sites. The bad way to do it is by going to the actual Flatpage admin source django/contrib/flatpages/admin.py and create a method which will display sites for a Flatpage on the change list page.
I am basically looking for a way to overwrite a django.contrib application on the admin side.
You don't need to edit flatpages/admin.py. Instead, create a CustomFlatPageAdmin that inherits from the default FlatPageAdmin.
You might want to create a customflatpage app for the following admin.py file, or perhaps you already have a utilities app that you can add it to.
#admin.py
from django.contrib import admin
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatPageAdmin
def get_sites(obj):
'returns a list of site names for a FlatPage object'
return ", ".join((site.name for site in obj.sites.all()))
get_sites.short_description = 'Sites'
class CustomFlatPageAdmin(FlatPageAdmin):
list_display = ('title', 'url', get_sites)
#unregister the default FlatPage admin and register CustomFlatPageAdmin.
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, CustomFlatPageAdmin)