I have three app in my project first app does not have any model while the the second app has two models which have been registered in admin site as given bellow.
admin.py for second app:
from django.contrib import admin
from .models import Country, CountryDetails
admin.site.register(Country)
admin.site.register(CountryDetails)
My third app has another model and I want to register its model in the admin site of second app, how can I do this.
I have tried this, Though I don't know wither its a right way to do it or not but its not working.
from django.contrib import admin
from .models import Country, CountryDetails
from thirdapp.models import Model_of_my_third_app
admin.site.register(Country)
admin.site.register(CountryDetails)
admin.site.register(Model_of_my_third_app)
showing an Error
Django “No Module Named URLs” error
Thanks
After struggling little bit I am able to figure out the problem, Actually I din't create a "urls.py" files for my "thirdapp", while I had included the given line:
url(r'', include('fastaapp.urls')),
Into myproject urls.py file, hence I have to create a "urls.py" file within a new app with a minimum content like this:
urls.py for "thirdapp" should be like this
from django.conf.urls import url
from . import views
urlpatterns = [
]
I am trying to override customer app in django-oscar. For that I have created customer app in my apps folder in project. While I run that project I encountered an error in django 1.7.4 as below:
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: customer
I went through the doc in django https://docs.djangoproject.com/en/1.7/ref/applications/#django.apps.AppConfig, But its not working out. So Is there any other way to extend any django-oscar's app and modify the code as per requirements.
This is my customer app's views.py:
from oscar.apps.customer.views import ProfileView as CoreProfileView
class ProfileView(CoreProfileView):
template_name = 'new_account.html'
and below is project's settings.py code snippet:
INSTALLED_APPS = [
'apps.customer',
]
Thanks in advance.
Run this command to overide apps from django oscar
./manage.py oscar_fork_app appname yourprojectname
yourprojectname-Your folder path to where the app should be created
Once you run this command a new app will be created with overided models,admin files.now add the app path inside
get_core_apps(['yourproject.order']) in settings.py file.
For more information please refer
http://django-oscar.readthedocs.org/en/latest/topics/customisation.html
This is my application structure:
/blog
/blog
/app.py
models.py
views.py
/admin
__init__py
views.py
...
I want to use flask-admin extension in a different package.
in /admin/__init__.py I imported the app and flask-admin extension:
from flask.ext.admin import Admin
from app import app
then I initiate the admin app like that:
admin = Admin(app)
However, I get 404 error. Why? Should I use blueprint or what?
I assume you're trying to hit the default /admin routes within your Flask app for Flask admin?
My guess right now is that none of your code does import admin anywhere, which is probably good since admin's __init__.py will try to re-import your app.py all over again (from the from app import app reference) and you'll end up in a circular dependency.
What I'd do is alter app.py to contain the admin = Admin(app) and from flask.ext.admin import Admin code, and also do a from admin import views and empty out the admin/__init__.py file completely.
I have a blog app inside of my own website app. The blog's objects (Posts, Comments) don't have the Add/Change buttons in the admin interface.
I used to have the admin code inside of my blog/models.py, but after reading this post I have moved the admin code in a separate file named blog/admin.py which looks like this:
from django.contrib import admin
from myapp.blog.models import Post, Comment
class PostAdmin(admin.ModelAdmin):
search_fields = ["title"]
admin.site.register(Post, PostAdmin)
class CommentAdmin(admin.ModelAdmin):
display_fields = ["post", "author", "created"]
admin.site.register(Comment, CommentAdmin)
However despite this change the add/edit buttons are still absent. I have admin.autodiscover() in my main app's urls.py. I also have admin as an installed app.
You should run below command after your changes
python manage.py syncdb
#then
python manage.py runserver
into your project root directory.
Edited
You must check your permission column into User section and make sure blog(add/edit/delete) option is given to that user .
as a django newbie (I have some exprience with other python webframework like turbogears and bottle but exploring django) I'm trying to auto create the admin management for my app model
in tha main URLS.py I have:
edit:
from django.contrib import admin
admin.autodiscover()
and after that:
urlpatterns = patterns('',
url(r'^appname/',include('appname.urls')),
url(r'^admin/',include(admin.site.urls))
notice this is in the main urls.py and not in the app urls.py
following the tutorial (which did work for me in the tutorial..) I created an 'admin.py' file in the appname folder and there:
from appname.models import Appname
from django.contrib import admin
class appnameAdmin(admin.ModelAdmin):
fieldsets = [various field sets and fields etc ]
admin.site.register(Appname,AppnameAdmin)
and in setting.py I have uncommented
'django.contrib.admin'
I don't get any error in the commandline window and the basic admin screen does appear (auth and sites)
I checked the imports in admin.py in the manage.py shell and everything seemed to work allright, I also tried commenting AppnameAdmin class out and registring just:
admin.site.register(Appname)
but that didn't work eith
I'm guessing I'm missing something obvious - I'll be glad to help with that
using django 1.4 + python 2.72
Check all of these:
There are seven steps in activating the Django admin site:
Add 'django.contrib.admin' to your INSTALLED_APPS setting.
The admin has four dependencies - django.contrib.auth, django.contrib.contenttypes, django.contrib.messages and
django.contrib.sessions. If these applications are not in your
INSTALLED_APPS list, add them.
Add django.contrib.messages.context_processors.messages to TEMPLATE_CONTEXT_PROCESSORS and MessageMiddleware to
MIDDLEWARE_CLASSES. (These are both active by default, so you only
need to do this if you’ve manually tweaked the settings.)
Determine which of your application’s models should be editable in the admin interface.
For each of those models, optionally create a ModelAdmin class that encapsulates the customized admin functionality and options for
that particular model.
Instantiate an AdminSite and tell it about each of your models and ModelAdmin classes.
Hook the AdminSite instance into your URLconf.
Do you have all the other admin dependencies in your installed apps?
Do you have admin.autodiscover() in your URLS.py?
Also, I think your code should look something more like this:
from projectname.appname.models import Appname
from django.contrib import admin
class AppnameAdmin(admin.ModelAdmin):
fieldsets = [various field sets and fields etc ]
admin.site.register(Appname,AppnameAdmin)
Have you restarted the server process?
Maybe this helps someone: in my case the problem was solved by stopping and starting the server process, because when you add a new admin.py file it does not reload automatically.
aaargghhh - I found the problem. I saved admin.py in the template/appname/ folder instead of the appname/ folder. so stupid of me. so sorry for the interruption.
Set this in your model admin:
def has_add_permission(self, request, obj=None):
return True
def has_change_permission(self, request, obj=None):
return True
def has_delete_permission(self, request, obj=None):
return True
Check all these:
Restart the server and check again
Add 'models.Model' as a parameter in your class in models.py file
class Classname(models.Model):
Add your app in the 'INSTALLED_APPS' in settings.py, In my case it's 'travello.apps.TravelloConfig'
INSTALLED_APPS = [
'travello.apps.TravelloConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Add 'admin.autodiscover()' in main urls.py
from django.contrib import admin
from django.urls import path, include
admin.autodiscover()
urlpatterns = [
path('', include('travello.urls')),
path('admin/', admin.site.urls),
]
it worked for me!
Nothing above worked for me.
Then I went to Settings, and under Project:MyApp Project Interpreter
I switched the Project Interpreter from Python 3.8(venv) to Python 3.8(MyApp)
And then all my models where registered (could list them in http://localhost:8000/admin/)
Strangely enough, still in admin.py, after "admin.site." the method registered will not be listed as available. But it works anyway.
Go to models.py file and add 'models.Model' as a parameter in your class .
Example:
class className(models.Model)
In your case use below as class name and it will 100% work for you.
class AppnameAdmin(models.Model):
from django.contrib import admin
from .models import modelname
admin.site.register(modelname)
import models in this way
Please consider that some models can be seen only from a superuser.
Try to create one and log-in the admin with that user.
python3 manage.py createsuperuser