Customizing Django Admin's verbose_name by init, using default - django

As I would use in version 2 of django the
default_app_config = 'catalog.apps.CatalogConfig' in __init__ to set verbose_name and customize django admin? It returns the error
'No Module named catalog'
Details: I use my apps to a directory below and in INSTALLED_APPS I put projectName.AppName

Your question isn't much clear (to me). What I understood is, you tried to customize the admin interface by adding verbose_name and during that process you got the error, 'No Module named catalog'.
If that so,
Initial you have to put the verbose_name name in your apps configuration class inside the apps module
# catalog/apps.py
from django.apps import AppConfig
class CatalogConfig(AppConfig):
name = 'catalog'
verbose_name = 'Fantasy Title'
and in your INSTALLED_APPS of settings.py, it should be either
INSTALLED_APPS = [
'catalog',
.....
]
OR
INSTALLED_APPS = [
'catalog.apps.CatalogConfig',
.....
]

Related

Django 3 installed_app shows ModuleNotFoundError in custom folders

while using customized folders, I am having a trouble using my app correctly in Django 3. My folder levels are:
--manage.py
--mdtour
----settings
-------settings.py
----apps
------core
----templates
In core app my apps.py file is:
from django.apps import AppConfig
class CoreConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'core'
But i cannot use my app in Django 3. In settings file I tried to add the app in two ways:
INSTALLED_APPS = [
'mdtour.apps.core.apps.CoreConfig.core'
]
The error I get:
`ModuleNotFoundError: No module named 'mdtour.apps.core.apps.CoreConfig'; 'mdtour.apps.core.apps' is not a packa`ge
or
INSTALLED_APPS = [
'mdtour.apps.core'
]
this time I get:
django.core.exceptions.ImproperlyConfigured: Cannot import 'core'. Check that 'mdtour.apps.core.apps.CoreConfig.name' is correct.
How can I correct this error?
Thanks
Either just name the module if you're running Django 3.2 (automatic AppConfig discovery):
INSTALLED_APPS = [
'mdtour.apps.core'
]
Alternately, name the appconfig class.
INSTALLED_APPS = [
'mdtour.apps.core.apps.CoreConfig'
]

virtualenv raises importerror because of changing app name in django

I've used [this link] to rename my django app. So I've edited some files and table's name and so on. But as it has been mentioned in that link, There is problem with virtualenv. So how can I fix it? I've change name "notes" to "blog".
The apps.py file:
from django.apps import AppConfig
class NotesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'blog'
In the settings.py file:
INSTALLED_APPS = [
'blog.apps.BlogConfig',
// the rest installed apps
]
Lets say the name of this application is: blog and its following the normal folder structure django comes with.
so, the settings.py should be
INSTALLED_APPS = [
'blog',
]
and the apps.py should be
from django.apps import AppConfig
class BlogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'blog'

Django Settings Apps Model

I want to know what is the meaning of "Config" in installed_apps in django like this
'polls.apps.pollsConfig'
Is it okay to put only the name of the apps example 'sample_apps'?
In the subfolder polls you have a file apps.py with a class named PollsConfig
polls/apps.py
from django.apps import AppConfig
class PollsConfig(AppConfig):
name = 'polls'
verbose_name = 'PollsApp'
This file is autogenerated by django when you create a new class but you can modify it to add some proprieties.

Safely importing models in django's middleware

I have been trying to import a model in a middleware process function but I am getting the error:
Value: Model class x doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS
I am guessing the problem is that the application setup is not complete, however, all my attempts to solve this have hit a wall.
middleware.py function
from notifications.models import Notification
...
class CheckNotificationMiddleware(object):
"""
Checks clicked notification to mark it as read
"""
def process_request(self, request):
if request.user.is_authenticated():
notification_id = request.GET.get('notification_id')
if notification_id:
AppConfig.get_model('Notification')
try:
notification = Notification.objects.get(
pk=notification_id, status=0, recipient=request.user)
notification.status = 1
notification.save()
except ObjectDoesNotExist:
pass
settings.py
INSTALLED_APPS = (
...
'notifications',
...
)
I have tried a couple of things including...
from django.apps import AppConfig
AppConfig.get_model('Notification')
I am using Django version 1.11 and python 2.7
you have to include notifications under the
INSTALLED_APPS = [
'notifications',
]
in the settings file

enable a model on Django Admin on Dreamhost

Hi I've created a new app (Paginas) but I cannot see inside the admin page. I've added 'paginas' to INSTALLED_APP. My admin.py is
# coding=utf-8
from django.contrib import admin
from .models import Pagina
class PaginaAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("titulo",)}
list_display = ('titulo' , 'contenido')
class Media:
js = ('/layout/grappelli/tinymce/jscripts/tiny_mce/tiny_mce.js','/layout/grappelli/tinymce_setup/tinymce_setup.js')
admin.site.register(Pagina,PaginaAdmin)
I am using passenger_wsgi.py file, I've touched tmp/restart.txt file, I've killed python process
I don't know what else can I do
The project you can see it on github https://github.com/totechess/paralisis_cerebral
What kind of error do you get when you go to your site yoursite.com/admin/
Did you add admin to INSTALLED_APPS? Note the S
....
'django.contrib.admin',
....
Perhaps your urls.py are not updated properly? What is the error?