Django staticfiles app help

I implore you to read the howto docs here: http://docs.djangoproject.com/en/dev/howto/static-files/ In short: STATIC_ROOT is only used if you call the collectstatic manangement command. It’s not needed to add the directory to the STATICFILES_DIRS setting to serve your static files! During development (when the automatic serving view is used) staticfiles will automatically look for static files … Read more

How to filter objects for count annotation in Django?

Conditional aggregation in Django 2.0 allows you to further reduce the amount of faff this has been in the past. This will also use Postgres’ filter logic, which is somewhat faster than a sum-case (I’ve seen numbers like 20-30% bandied around). Anyway, in your case, we’re looking at something as simple as: from django.db.models import … Read more

How to automate createsuperuser on django?

If you reference User directly, your code will not work in projects where the AUTH_USER_MODEL setting has been changed to a different user model. A more generic way to create the user would be: echo “from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser(‘admin’, ‘[email protected]’, ‘password’)” | python manage.py shell ORIGINAL ANSWER Here there is a … Read more