Django-autocomplete-light does not show search box for selecting OneToOneField - django

I am trying to use autocomplete in admin page to auto select a field(OneToOneField) before saving, I am following the tutorial to add a field in admin.
I am not able to see the search box to type in my selections. I tried replicating the select2_one_to_one app from the test project: https://github.com/yourlabs/django-autocomplete-light/tree/master/test_project
I am see the same issue for this app as well. Attaching a screeshot of the issue
Screen shot of the select2_one_to_one app

After trying different things for couple of days. In Inspect I figured that the static files were not being loaded same as the demo project in the documentation (http://dal-yourlabs.rhcloud.com/admin/)
I had to update the STATIC_ROOT(Location used while running 'python manage.py collectstatic') folder and run the collectstatic command. The static files for autocomplete_light were copied to STATICFILES_DIRS. After this the autocomplete started working.
Documentation mentions we need to understand handling static files. So this is what they might have been referring to.

Related

Django Admin Styling corrupted

I recently made some changes to my django site, one big one being upgrading from Django 2.2 to 3.1. Now my admin site styling is all messed up. I can't figure out what went wrong or how to fix. Any pointers would be appreciated!
See image of what it looks like after update....
The main home page for admin looks fine, but when I click on one of the models to view, the formatted is definitely not correct.
Also, some not all, of my images on the site are saying 404 not found...
It looks like your browser is caching the CSS / JS from the old version, you can clear your cache and reload. In chrome use ctrl + shift + r to reload.
I was facing the same problem, First I thought it was a Cache issue but it wasn't.
I checked the page source and found a css file being applied to the page which wasn't even present on my drive.
In my case the file was:
static/admin/css/nav_sidebar.css
So I created new file in static/admin/css named nav_sidebar.css,
then copy pasted the code which I got from page source and
added "display:none;" in the #nav-sidebar section(line:34) and [dir="rtl"] #nav-sidebar section(line:45 in my case).
You can find the Original code here by using Google Chrome's inspect tool.
Where to find the code
I had the same issue after bumping django from v3.0 to v3.1. I run python manage.py collectstatic to update css which solved my issue
I was experiencing the same styling as the OP's screenshots.
I had upgraded incrementally from 2.2 -> 3.0 -> 3.1 -> 3.2. I only experienced the styling issues in 3.2
The issue was that there were legacy admin styles committed to the repo in the static folder. To resolve, all I did was delete the committed admin styles, and Django then appeared to use its own styling
I was upgrading from 3.0 to 3.2 and I tried a couple of the answers here without luck. At the end, the following procedure solved it for me:
manually delete the content of the directory STATIC_ROOT (see in settings.py what you named the folder)
run the command python manage.py collectstatic This will repopulate the directory with the newst files
hard refresh your page (ctrl + F5)
I think the other answers here are necessary, but I'll add one more: You might have to bust caches in your server itself. In our example, nginx was configured to provide really long caches to our static files, so we just had to reset it to make changes come through.
Ok maybe I am late to the party but it may help others,
What works for me is:
Set STATIC_ROOT in settings.py (I guess it should be already there as project is old one)
Comment STATIC_DIR in STATICFILES_DIRS list (otherwise it will give error) and run python manage.py collectstatic
Clear browser cache.

PythonAnywhere image not found

Before anyone deletes this due to the question being similar to others: Neither other questions nor the documentation got my site to work as intended.
The goal: Load images on my site
The problem: Image not found
Additional info: It works locally using python manage.py runserver
What I've done to try to fix it:
I've tried to follow the staticfiles guide https://help.pythonanywhere.com/pages/DjangoStaticFiles but this didn't work because I'm not using the default uploaded files handling.
I've tried to enter it under the PythonAnywhere > Web > static files tab but haven't been able to get that to work.
Tried a bunch of different solutions from the PythonAnywhere forum and SO forum and none got my site to work.
The site: http://nasablogdeployment.eu.pythonanywhere.com/
All code available here: https://github.com/MarkdenToom/NASA-blog
Static files directories here: https://imgur.com/xL0RN8A
WSGI file content: https://imgur.com/dJY4knp
Your web app is looking for the picture in http://nasablogdeployment.eu.pythonanywhere.com/blog/media/thumbnails/Touchdown_Expedition_62_Returns_to_Earth_Completes_Station_Mission.jpg while your current mapping resolves into url like that: http://nasablogdeployment.eu.pythonanywhere.com/media/thumbnails/Touchdown_Expedition_62_Returns_to_Earth_Completes_Station_Mission.jpg
Change your static files mapping so the /blog/media/ points to /home/nasablogdeployment/NASA-blog/blog/media/

Django Admin wont allow me to allocate permissions to Users or Groups

I am using django 1.8.6 and have a new application created in a virtualenv using python manage.py startproject. I have set up my INSTALLED APPS and my database settings (postgresql) and I have run migrate to create the backend. So far all seems fine. I then created a superuser using the createsuperuser command and that all seemed to go fine too. My admin.py file is in place and the content of which is as follows:
from django.contrib import admin
from django.contrib.admin import AdminSite
from myapp.models import mymodel
Class mymodelAdmin(admin.ModelAdmin):
list_display = {col1, col2, col3}
admin.site.register(mymodel, mymodelAdmin)
All what appears to be fairly simple standard stuff, so far so good.
I'm using apache to render my webpages and having configured my virtualhost stuff I can happily log in to my admin page and see everything I have registered plus the default django admin stuff. I can create a new user with no problem and I can create a new Group with no problem. Where I am running into trouble is I ma not able to assign any standard permissions to with my new user or my group. I can see the list of permissions from my database with no problem but the button that I need to click to move a permission from available to assigned seems to be disabled and I cannot find any information anywhere or in any tutorials or blogs that might help me to unravel this issue. I have been able to replicated this on every installation that I have done following various different tutorials but I still end up with the same problem.
Can anyone please shed any light on what I am missing? Thanks in advance.
UPDATE: So there seems to be an issue with my static files. I have yet to create any static files of my own for the app so the only static files are the ones installed when I use pip to install everything. I'm using a virtual environment (env) inside my project and the structure is as follows:
/var/www/<my project>/env
/manage.py
/<my app>/settings.py
/urls.py
/wsgi.py
/templates
/static
/media
My project static directory is empty as I believe that collectstatic should collect all the static files and put them in here. All the other static files are stored in the site-packages directory within my virtual environment but clearly they are not being accessed. Any help on this would be gratefully received.
Problem Solved...Hoorah! This was a tough one because everything looked fine except for one little thing. Permissions! However the issue wasn't with permissions at all. A red herring I'm afraid. The issue was all to do with static files and trying to get your head around what's going on and making sure you've got your paths all sorted.
For newbies the key is to specify your main static files directory as an empty directory. This is intentional as the collectstatic routine will populate it for you. It seems to me that you should run this routine after you have installed any apps or plugins that you have defined in INSTALLED_APPS. This routine will go off and find all the static files that these apps need to work properly and will copy them to your base static directory. (Make sure you set the permissions to this directory properly otherwise it wont write the new sub-directories etc.) Once copied you will see in your static directory a list of sub directories containing each set of static files separately so as they don't override each other. Follow this theory and all will work fine. By extension when you create your own static files for your applications, you should keep them in a separate static directory located in your folder. Within this you should have another directory named the same as your app and all your static files should be stored in there. Then when you run the collectstatic routine again, it will copy all your static files to the base static directory and store them neatly in your own app's sub directory so as not to conflict with others.
So in essence you have two static folders at the following paths:
/var/www//static (left empty at the same level as manage.py)
/var/www///static/
I have read a lot (and torn a lot of hair out) to get to this point. Somewhere I read someone's post who said that the base static directory (the empty one) is a red herring and you should delete it. I believe this is wrong advice.
Phew! Got there and hope this helps someone else.

Cmsplugin-Nivoslider plugin for Django-CMS

I am new to Django-CMS, I have successfully installed Django-CMS on my Ubuntu 12.04 (64-bit OS). I want to add Nivo Slider on my web page using Cmsplugin-Nivoslider. After following steps mention in https://bitbucket.org/bercab/cmsplugin-nivoslider/overview, I am able to install cmsplugin-nivoslider on my Django-CMS. After syncdb, migrate and collectstatic commands, I am able to see nivo folder with js, theme and css files in my static folder, but I am not able to see anything on my Admin Panel related to Nivo Slider. Please tell me, do I need to do any further steps to use nivo-slider, How can I put that slider on my page ? Please guide me..
Thanks in Advance.
From the Admin interface, Add or edit a Page, you should have available a plugin for slider if the chosen template has a block &/or placeholder tag. Configure gallery from there.

Admin media disappear while running django trunk in development mode

I got into django recently and start playing around with the tutorials & documentation (with the development version). Everything has been fine till I decide to update again to the latest django trunk and well my admin media are not showing up at all!
After some troubles, I managed to get admin media showing by commenting out django.contrib.staticfiles. However as I do use the staticfiles app to manage my site static files, I need it to be enabled. After some troubles, I manage to get both admin media and staticfiles showing by using manage.py collectstatic to collect the admin media files to my static folder.
However is there a way for me to serve admin media in DEBUG mode easily like last time without using collect static command? as I don't want to call the collectstatic every time when django admin media files got changed in trunk? (though I don't know how often/rare that is)
Django trunk is changing how static files are served, and in fact new changes landed this morning.
You'll want to get latest again, and then start here: http://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/