After installing django 1.9 I'm having problems trying to show my apps in the Admin interface, this is my code:
app name: people
#models.py:
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=100)
#admin.py:
from django.contrib import admin
from .models import Person
admin.register(Person)
#apps.py
from django.apps import AppConfig
class PeopleConfig(AppConfig):
name = 'people'
#settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'people'
]
I changed the last line of INSTALLED_APPS to 'people.apps.PeopleConfig' without success. Python version 3.5
I found the problem
#Change:
admin.register(Person)
#To this:
admin.site.register(Person)
Sorry.
Related
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 have a problem with overwitten model from Django oscar. I want add a new field to model but when i do it i have RuntimeError: Conflicting 'order' models in application 'order': and .
Thats my code
myapp.oscar_apps.order.models.py
from oscar.apps.order.models import * # noqa
from oscar.apps.order.abstract_models import AbstractOrder # noqa
from django.db import models
class Order(AbstractOrder):
hash = models.CharField(max_length=256, blank=True, null=True)
from oscar.apps.order.models import *
*myapp.oscar_apps.order.init.py
default_app_config = 'bakdrop.oscar_apps.order.config.OrderConfig'
*myapp.oscar_apps.order.config.py
from myapp.apps.order import config
class OrderConfig(config.OrderConfig):
name = 'myapp.oscar_apps.order'
Can anybody help my solve this problem ?
Update my INSTALLED_APPS
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.flatpages',
'compressor',
'paypal',
'crispy_forms',
'django_select2',
'myapp.apps.user',
'myapp.apps.organization',
'widget_tweaks',
'djcelery',
] + get_core_apps([
'myapp.apps.promotions',
'myapp.oscar_apps.checkout',
'myapp.oscar_apps.order',
'myapp.oscar_apps.basket',
'myapp.oscar_apps.shipping',
'myapp.oscar_apps.payment',
])
Instead of doing
from oscar.apps.order.models import *
I think you need
from myapp.oscar.apps.order.models import *
A good debugging strategy for this is to comment out all of these, and reintroduce them line by line. That way you can pin-point the error:
get_core_apps([
'myapp.apps.promotions',
#'myapp.oscar_apps.checkout',
#'myapp.oscar_apps.order',
#'myapp.oscar_apps.basket',
#'myapp.oscar_apps.shipping',
#'myapp.oscar_apps.payment',
])
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'
directory stucture
tutorial/tutorials
turotial/tutorial
tutorial/settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
#'domains'
'tutorials'
)
tutorials/admin.py
from tutorials.models import Tutorial
from django.contrib import admin
admin.site.register(Tutorial)
# Create your views here.
tutorials/models.py
from django.db import models
class Tutorial(models.Model):
name = models.CharField(max_length=200)
url = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class User(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class Country(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
Few things to help finding the problem:
Do you have admin.autodiscover() in your urls.py
Have you run syncdb
Have you tried to open manage.py shell and import the model to see if there are errors.
You probably do not have an entry in your INSTALLED_APPS setting for this app.