Friday, September 4, 2020

Django - Duplicate Unformatted Logs

Recently I worked on a bug that was causing duplicate unformatted log messages to appear in a Django app's logs. I made a repository that demonstrates the issue:

The problem was caused by an accidental call to (without using logging.getLogger to get a specific logger) while the root logger isn't already configured.

The solution ended up being to get rid of the accidental calls to and configuring the root logger to prevent it from accidentally happening again. I go into more details in that repo.

Monday, May 11, 2020

Vue - vue-custom-element

Vue-custom-element seems like the best way to integrate vue into an existing application that uses server side templates.

This approach allows you to use vue components (built with the build pipeline) in your existing html without making your entire application a SPA.

Initially I started following this guide:

Vue-custom-element turned that code into 3 lines and allowed using components like normal (without the data attributes).

This approach seems much better than: Which doesn't allow for using a build pipeline for babel, linting, testing, single page components, live reload, modules with import/require, etc.

Targeting your builds for web components might do the same thing: It says it's not compatible with IE11, but that might not be a big deal in most situations.

Tuesday, May 5, 2020

Django - Requiring Prefetching

I made a repository to try to figure out the best way to require prefech_related/select_related when fetching a model's related objects. I also want to figure out a good pattern for avoiding duplicated prefetch_related/select_related for multiple places in a codebase that need the related objects eager loaded in the same way.

Wednesday, April 29, 2020

Nginx - WebDAV

Just learned Nginx has WebDAV support:

It's a lot faster than the Python package I was using:

Wsgidav is great though. It's super customizable and the documentation is great too.

Wednesday, April 22, 2020

Django - ModelChoiceField queryset caching

It would be nice to know a better way to cache the ModelChoiceField's queryset when it's used in a form that runs "is_valid()" in a loop (like Formsets do). The best way I know how at the moment is by not using a ModelChoiceField at all. The solution requires using a ChoiceField, running the query for choices outside of the loop, then passing the choices into the form to override the ChoiceField choices.

Here's an example:

Django API Forms

Just found a really cool library for using Django's built-in forms to validate JSON:

I made a small example with it to show how it works with ModelChoiceFields:

Seems like a more lightweight version of DRF's serializers (but only for deserializing and validating) and with a similar API to Django's built-in forms.

Saturday, April 18, 2020

Learning Vue Through Terrible Pull Requests

I made a pull request asking to "remove the unused public/index.html" file from django-vue-template:

Well, the author responded and it turns out it's definitely used (by vue magic):

Oops, definitely should have googled "vue public/index.html" before making that pull request. I made another pull request to add a link about it to the django-vue-template docs: