I used this admin code, to adjust my
class CustomUserAdmin(UserAdmin):
list_display = UserAdmin.list_display + ('show_url', 'date_joined')
def show_url(self, obj):
return format_html("<a href='{url}'>Link</a>", url=obj.extendeduser.get_link())
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)
But the admin just seems to ignore this and displays the old admin page. What could i have missed?
The code is placed in an admin.py of an app I called "main", which is listed in the INSTALLED_APPS list:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
'main',
...
]
To create custom user admin pages easier, see: django-authtools.
Related
When I run python manage.py runserver in Django, I get the following error.
Error
django.core.exceptions.ImproperlyConfigured: Cannot import 'account'. Check that 'accounts.apps.AccountConfig.name' is correct.
I tried everything but could not figure it out.
What should I do?
acconuts/apps.py
from django.apps import AppConfig
class AccountConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'account'
mysite/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'widget_tweaks',
'app',
'accounts',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
]
Instead of account your app is named accounts. Also, you shared file acconuts/apps.py - is that also your mispell?
class AccountConfig(AppConfig):
...
name = 'accounts' # it has to be exactly as your app name
This is how it is structured
The code inside apps.py of accounts folder file is
from django.apps import AppConfig
class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = "apps.accounts"
The code inside Settings is
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mysite.apps.accounts',
]
I tried changing 'mysite.apps.accounts', to 'mysite.apps.AccountsConfig',
and changing name = "apps.accounts" to name = "accounts"
I am new to Django and was following How to make a website with Python and Django - MODELS AND MIGRATIONS (E04) tutorial. Around 16:17 is where my error comes up when I enter python manage.py makemigrate to the vscode terminal
The error is
ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured:
Cannot import 'apps.accounts'. Check that
'mysite.apps.accounts.apps.AccountsConfig.name' is correct.
Someone please help me.
The name in apps.py should be the same (value) that you put in INSTALLED_APPS (in settings.py).
That's the correct one
from django.apps import AppConfig
class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = "mysite.apps.accounts"
settings code
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mysite.apps.accounts',
]
The solution was quite counterintuitive. You have to delete the
class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = "accounts"
from apps.py\accounts\apps\mysite. Then run python manage.py makemigrations and 2 new models 'UserPersona' and 'UserProfile' are created. the output in the terminal:
mysite\apps\accounts\migrations\0001_initial.py
- Create model UserPersona
- Create model UserProfile
To define new app you do not need to add it's path just
app it's name like that 'accounts' note that app name is case sensitive
so your installed app became :
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
]
The name in AppConfig should be same as the name provided in Installed Apps i.e., it should be "mysite.apps.accounts".
I successfully imported and exported other data but not able to import/export social accounts and social application tokens. I am using django allauth for social account creation. There is no other way to login in.
settings.py
INSTALLED_APPS = [
'channels',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'user_sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'authapp',
'thanoschats',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'import_export',
]
admin.py
from import_export.admin import ImportExportModelAdmin
from django.contrib import admin
from .models import MyUser
#admin.register(MyUser)
class UserProfileData(ImportExportModelAdmin):
pass
I have two different Django Apps, one of them is fileUpload. In File Upload I added a Generic Relation as:
from django.db import models
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
class FileAttachment(models.Model):
file = models.FileField(upload_to='fileuploads/%Y-%m-%d/')
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
attachee = generic.GenericForeignKey()
In my other app named XYZ I added following reverse generic relation in models.py
attachment = generic.GenericRelation(FileAttachment)
Now, so if I run manage.py syncdb or any other manage command, I get error: NameError: FileAttachment
IN installed Apps I have following stuff:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.markup',
'django.contrib.humanize',
'south',
'taggit',
'taggit_autocomplete_modified',
'compressor',
'bootstrapform',
'fileupload',
'XYZ'
)
Both apps, XYZ and fileupload are on same root level.
I am using Django 1.5 with Python2.7
Did you import the FileAttachement in the XYZ models?
Try this in XYZ/models.py:
from fileupload.models import FileAttachment
I have my directory structure like this for my Django application:
project
__init__.py
settings.py
...
users
__init__.py
model.py
....
In my model.py I have this class:
class User():
...
However when I configure my INSTALLED_APPS like this:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
'users'
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
Django cannot find the application users. What am I doing wrong?
Change model.py to models.py, or if you want to use a different name for your module append the app_label argument to your models Meta classes:
class YourModel(models.Model):
# fields...
class Meta:
app_label = 'users'