Django Static Files Development

Based on what you’ve posted so far, it looks like you’re following the docs for django.contrib.staticfiles. I agree that the docs can be difficult to follow especially if one is new to django. I believe the confusion stems from the fact that django.contrib.staticfiles has two modes of operation: During the development phase where the development … Read more

Django unique, null and blank CharField giving ‘already exists’ error on Admin page

None of the answers clearly describe the root of the problem. Normally in the db you can make a field null=True, unique=True and it will work… because NULL != NULL. So each blank value is still considered unique. But unfortunately for CharFields Django will save an empty string “” (because when you submit a form … Read more

Django AdminForm field default value

Assuming the value is based on ‘request’ you should use this: class MyModelAdmin(admin.ModelAdmin): def get_form(self, request, obj=None, **kwargs): form = super(MyModelAdmin, self).get_form(request, obj, **kwargs) form.base_fields[‘my_field_name’].initial=”abcd” return form

How to get two random records with Django

The order_by(‘?’)[:2] solution suggested by other answers is actually an extraordinarily bad thing to do for tables that have large numbers of rows. It results in an ORDER BY RAND() SQL query. As an example, here’s how mysql handles that (the situation is not much different for other databases). Imagine your table has one billion … Read more

How to fix VersionConflict locking failure in pipenv?

Here are my debugging notes. Still not sure which package is causing the problem, but this does seem to fix it. The error you get when you first run pipenv install with pipenv version 2020.8.13. Traceback (most recent call last): File “/usr/local/bin/pipenv”, line 8, in <module> sys.exit(cli()) File “/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py”, line 829, in __call__ return self.main(*args, … Read more