I'm using django-geoposition in a project and added it to my admin with a GeopositionField() in my models.py.
class MyClass(models.Model):
position = GeopositionField()
When I access it, it shows the lat, long field, but not the google map.
There are no errors in the browser console.
I have the application configured correctly in settings.py: INSTALLED_APPS and GEOPOSITION_GOOGLE_MAPS_API_KEY.
Django version==1.11.5
What can cause this?
It's a django-geoposition problem.
I found it and a workaround in:
https://github.com/philippbosch/django-geoposition/issues/83
Related
I've been trying to unregister the admin for sites in django by doing the following:
from django.contrib.sites.models import Site
admin.site.unregister(Site)
However this gives me an error stating that "Site" is not registered (even though it showed up in admin before).
If I try doing the following I get no errors but "Site" stays in the admin:
from django.contrib.sites.models import Site
admin.site.register(Site)
admin.site.unregister(Site)
I need the sites app and cannot take it out of INSTALLED_APPS in settings. However the admin for it is utterly useless to me.
Any ideas on what I am doing wrong here?
Thanks!
The order of your INSTALLED_APPS setting is important.
When Django starts it will import the applications in INSTALLED_APPS in the order they are defined (https://docs.djangoproject.com/en/1.11/ref/applications/#how-applications-are-loaded). In your example above you were unregistering Site before Django had the chance to register is it.
There isn't much you can do in terms of troubleshooting except for reading the logs very carefully. After staring at them for a while you either become one with Django and understand it all, or you come here like the rest of us ;-)
My INSTALLED_APPS usually start with the django.contrib apps, then any 3rd-party applications, then my apps at the bottom. I only change this if I have a very good reason to.
I am running a site live on heroku. My issuse occurs when I visit my site's admin located at www.mysite.com/admin. When I visit this page, I get
DoesNotExist at /admin/
Site matching query does not exist.
Thing is, my project /admin works locally as well as on my staging server. It just so happens when I visit it live, I get that error.
After looking around SOF, I tried doing running python manage.py shell with the following commands:
from django.contrib.sites.models import Site
Site.objects.create(pk=1, domain='www.xxx.com', name='xxx.com')
and I changed SITE_ID = 1 to SITE_ID = www.mysite.com and that just ended up breaking my staging server, so I changed it back and tried again without changing the SITE_ID.
What could be the issue?
It seems the SITE_ID setting in your settings file is pointing to an ID that doesn't exist in your database.
You either need to create a new site in the sites model (via admin) and change the ID in the settings file to match that one, or re-insert the item via SQL and give it the same ID as your settings file.
This problem will always seem to occur continually, so if you don't want to serve your model with multiple sites, then I suggest you remove the SITE_ID from the setting file. Note this worked for me!
I just had to remove the 'django.contrib.sessions' from INSTALLED_APPS in settings.py as it was causing problems and I was using this project only for one site.
However, if you are using your project for multiple different sites and need the Django sites framework, please check SITE_ID in your database and if it matches the one defined in the settings.
I have a django test site and I can see the admin site, but it has different formatting from the tutorial examples.
This is how my admin site looks:
But on the example it looks like this:
What is missing to show the correct formatting?
Looks like your CSS file isn't being loaded. Make sure your django install is set up correctly to server out static files. The CSS file, by default, is in /static/admin/css.
uncomment 'django.contrib.staticfiles' under INSTALLED_APPS from settings.py.
I installed Django and enabled the admin site. When I go to the admin page, I get the following
The image does not look the official Django tutorial. In settings.py I updated TEMPLATE_DIRS with the correct path.
TEMPLATE_DIRS = (
"/var/www/mysite/templates/admin"
)
I also tried restarting Apache many times. Any suggestions on what I might be doing wrong? Thank you.
It's an issued related to static files rather than templates:
https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-production
Use the developer tools on your browser to looks at what requests are being made. Most likely some static files like CSS, etc. are not being served up.
Is there a way to implement the permissions for models through the code? I have a large set of models and I want some of the models to be just viewable by the admin and not the ability to add them.
Please suggest.
You can set permissions through the admin site itself. For instructions, see the "Users, Groups and Permissions" section in the django book chapter:
The Django Administration Site
Found the solution here: http://code.djangoproject.com/wiki/RowLevelPermissions
works the way I needed.