Python Strategy Pattern
The strategy pattern can be a nice way to improve flexibility when accessing external resources. For example an application might have images referenced in Flickr and a relational database. You want to...
View ArticleExample Django Model Count and Group By Query
The Django framework abstracts the nitty gritty details of SQL with its Model library (the M in MVC). It is straight forward for standard lookups involving WHERE clauses. 10% of the time I need it to...
View ArticleDjango Automatic Slug Generator Abstract Class
Using Django, an example of how to auto populate a slug field based on the name or title of whatever the thing is. Correctly handles duplicate values (slugs are unique), and truncates slug if value too...
View ArticleDjango – Correctly Wiring to AWS CloudFront for Static and Media Files
When it comes to “How To Setup a CDN for Django” most people suggest the following “half way” setup that can lead to stale cache problems and slowness in the admin. Configure Django to upload media and...
View ArticleDjango Tricks for Processing and Storing JSON
In this post I’ll show a few tricks I use to make JSON fit into Django more seamlessly. The first is a lesson on coding that everybody should know. Parsing external JSON: Whenever you take in JSON from...
View ArticleQuerying Complex Data in Django with Views
Django has a powerful ORM, but like any ORM it suffers when querying data that has complex relationships. Django supports foreign keys and many to many relationships out of the box with ease. Sometimes...
View ArticleGetting back lists of data from the ChatGPT API
I’m working on a project where I’m trying to harvest lists of data from ChatGPT via its API. This post applies to the gpt-3.5-turbo model called via the API. I don’t have access to the GPT 4.0 API yet,...
View ArticleVisualizing Relationships in ChatGPT
The other day I asked ChatGPT for some recommendations for new piano pieces based on one I had just finished. To my astonishment the list it provided was pretty good and lead me to a new piece I...
View ArticleHow To Make Python Code Run on the GPU
As a software developer I want to be able to designate certain code to run inside the GPU so it can execute in parallel. Specifically this post demonstrates how to use Python 3.9 to run code on a GPU...
View Article