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
Related
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.
Has anyone seen this before? I've tried making new apps, projects, etc.
All thats in my admin.py file is:
from django.contrib import admin
from . models import UserProfile, Tribe, Membership
# Register your models here.
admin.site.register(Tribe)
admin.site.register(Membership)
admin.site.register(UserProfile)
I've not got any static files or css in the app..?
Create a class that inherit admin.ModelAdmin, update the fields to be shown in the list_display tuple, and register TribeAdmin instead of Tribe. Do the same for the rest.
from django.contrib import admin
from . models import UserProfile, Tribe, Membership
# Register your models here.
class TribeAdmin(admin.ModelAdmin):
list_display = ('field_1', 'field_2',)
admin.site.register(Tribe, TribeAdmin)
# admin.site.register(Membership)
# admin.site.register(UserProfile)
For all the available options, have a look at the documentation or an easy to understand beginner tutorial from the DjangoBook (please note its for an outdated Django Version, but fields works with Django 1.8)
With Django 1.8 you can use.
#admin.register(Tribe)
class TribeAdmin(admin.ModelAdmin):
list_display = ('field',)
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)
Hi ive not be able to find any one trying to solve this issue yet so i thought id ask the question here. Basically im trying to add an image field to the admin.auth users admin site that relates to my userprofile model.
Aswell as users that register to the site, the admins need to be able to specify a profile picture when the create a user in the admin site that will be used for posts they make to news and blogs etc.
Is this at all possible, i have the userprofile model working which will allow me to add the image but i want to include this in the admin user panel when an admin creates a new user.
Any help is greatly appreciated!!
Thanks in advance
You can add your UserProfile (with the extra image field) as an inline to the User adminModel. So when you go to the admin.auth panel to add a new user, there will be an inline below it with all the UserProfile fields.
Something like this should do it (in admin.py of whatever app your userprofile is in):
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.contrib import admin
class UserProfileInline(admin.StackedInline):
model = UserProfile
class UserModelAdmin(UserAdmin):
inlines = [UserProfileInline,]
admin.site.unregister(User)
admin.site.register(User,UserModelAdmin)
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)