1

I'm having trouble understanding how static files are handled in Django. I've read through the official Django documentation as well as multiple threads, including this wonderful one here:

Differences between STATICFILES_DIR, STATIC_ROOT and MEDIA_ROOT

Most people define the STATICFILES_DIRS list as a list of paths where django will search for additional static files aside from the app's static folder.

I understand that, but what does this have to do with the formfields I'm overriding in my admin.py? I have overridden the default ManyToMany form to the FilteredSelectMultiple widget in a few of my admin models like so:

from django.contrib.admin.widgets import FilteredSelectMultiple

formfield_overrides = {
    models.ManyToManyField: {'widget': FilteredSelectMultiple("User Names", is_stacked=False)}
}

This works fine and produces the widget override I wanted: Functional Widget Screenshot

However, when I define STATICFILES_DIRS in settings.py to include my root static folder like so:

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static/'),
)

It breaks my override and defaults back to the original ManyToMany field form: Broken Widget Screenshot

We do not have STATIC_ROOT defined in our settings.py as we don't plan on using the collect static feature. We plan on keeping/referencing our static files at the root static folder. Also in our settings.py we have:

STATIC_URL = '/static/'

I don't understand how these settings for dealing with static files are interfering with the formfield_override above. I would appreciate some insight on this, so that I could find a way to approach this issue.

Thank you!

Yamen Alghrer
  • 651
  • 6
  • 12

1 Answers1

0

I figured out the cause of my issue. I missed this portion in the Django documentation that explains STATICFILES_FINDERS: STATICFILES_STORAGE Documentation

enter image description here

It turns out that my production server was finding the static files in my outer root folder first, which were not up to date. This explains why I wasn't seeing my changes. I'm going to reconfigure the way I handle static files to ensure that the outer root static folder that my production server looks always has the latest static files via the collectstatic feature

Yamen Alghrer
  • 651
  • 6
  • 12