python


Django - AttributeError: 'module' object has no attribute 'admin'


I'm in trouble.
Python version: 3.4.4
Django version: 1.10
DB type/version: SqlLite3
Installed apps: accounting, registry, ...
Models (accounting): Bank, Fee, ...
Models (registry): Company, ...
Generic relations: Company-Bank, Fee-Company, ...
Admin site inline (accounting):
class FeeAdmin(Admin):
list_display = ['date', 'content_object']
inlines = [registry.admin.CompanyInline]
...
Admin site inline (registry):
class CompanyAdmin(Admin):
list_display = ['__str__', 'contact_telephone', 'contact_cellphone', 'contact_email']
list_filter = Admin.list_filter + ['residence_city']
search_fields = ['company_name']
inlines = [accounting.admin.BankInline]
...
Problem: the second installed app gives me the error in the title, if I switch the order in settings.py, the error is raised by the other app. The first one always run smoothly:
inlines = [registry.admin.CompanyInline]
AttributeError: 'module' object has no attribute 'admin'
if registry is installed after accounting, or
inlines = [accounting.admin.BankInline]
AttributeError: 'module' object has no attribute 'admin'
if the order is switched.
Headers:
accounting.admin:
from django.contrib import admin
from django.contrib.contenttypes import admin as ctadmin
from django.contrib.contenttypes.models import ContentType
import registry
from .models import Bank
from .models import Fee
...
registry.admin:
from django.contrib import admin
from django.contrib.contenttypes import admin as ctadmin
from django.contrib.contenttypes.models import ContentType
import accounting
from .models import Company
...
This is a question about Python imports.
When you import a package, you don't automatically get access to all the modules underneath it; you need to import those specifically. So instead of doing import accounting and then trying to access accounting.admin, you need to explicitly do from accounting import admin and then accessing admin.BankInline etc.

Related Links

How to create list of all parts of elements in NumPy array (Python list)
Encoding issue for Python tool Unidecode on CL
Accept only numbers on a python string [closed]
scrapy spider pass parameters
sending data to particular client from twisted server
Type Error, object cannot be interpreted as an index with tk message box bind commands
What is this condition testing? [duplicate]
Testing Flask login and authentication?
Pyjnius import jar file
Regex - Combining an 'or' with a 'look-behind'
Command fails in python, but not in terminal
Does ndb.toplevel break transactions?
Unique variables names for results in a nested loop
Get unique set of adjacent vertices in python bulbs or gremlin?
Django admin project distribution and management
Increase event handling speed in Twisted?

Categories

HOME
cakephp-3.x
dotnetrdf
crystal-reports
cntk
cluster-computing
ember.js
pug
elixir
drupal-7
uibutton
bower
aem
actionscript
mapbox-gl-js
tomcat7
search-engine
jscript
is-empty
goutte
diagram
wordpress-theming
maxima
sendkeys
netezza
ng-show
ms-access-2007
primes
flexlm
attask
statusbar
fop
source-maps
compare-and-swap
metadata-extractor
spring-data-neo4j
edge-detection
aurelia-binding
dhtmlx-scheduler
superscript
protobuf-net
entity-system
read-write
modulo
jboss-esb
readfile
spring-bean
catia
bids
rapidweaver
ajp
web-deployment-project
gist
rollback
windows-95
forerunnerdb
volume
modelattribute
sqlexception
barcode-printing
objloader
libtiff.net
verbose
android-navigationview
hspec
spring-ioc
git-annex
jackson-databind
com-interop
inet
xmp
jta
app.xaml
futuretask
on-duplicate-key
harp
criteria-api
jai
cpu-speed
kendo-mvvm
adcolony
outline
surrogate-key
korma
openkinect
mimosa
java.util.date
convex-polygon
qss
htmltextwriter
arbor.js
lync-server-2010
enumerators
vim-powerline
fotoware
flexicious
datamember
noir
audiostreamer
quick-search
camtasia
gwt-2.2-celltable
boost-date-time
windows-controls
callgrind
visual-studio-2010-beta-2
standardized

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App