And now we're Django/Python

Just because you can do something is enough reason to do it

Posted by Art Mills

April 11, 2024

Excited much?

Last year I joined my daughter in solidarity with her decision to attend the University of Minnesota by learning Golang and having a great deal of fun with it. She was a Gopher. So I WAS A GOPHER. I genuinely liked the simplicity and power in several tasks I built out. It helped me immediately at work, and I built this site, Hamcois.com using it.

That said, and though I remain firmly of the mind Golang has astounding potential, having spent several days with Python, though one couldn't say the language itself is faster, the community, tools and frameworks allow anything you do to be astonishingly more rapidly created.

When I made this site originally in Golang last year (having had it as Ruby/Rails for many years prior) there were things I wanted to do with this site that you had to do from scratch. That was really cool learning all that. But some things took a while.

Take my slogan model here.

Every time you refresh a page you get a new subheading with a clever phrase I've written. This is not a user facing feature, but, is for me to add to as I find something clever -- to me at least -- I want to jot in. With my Golang personal site, I made this as you would. Standard model/view/controller, building it out for every CRUD action.

This was great. Straightforward. Easy.

With Django how did I accomplish this?

Well, I created a Django app with:

django-admin startapp slogans

Then I went and registered the app, and customized it, within the admin.py file within the app, as so:

# Register your models here.
from . models import Slogan

# Register the Slogan model with the admin site with customization
# Customizing the admin interface for the Slogan model
@admin.register(Slogan)
class SloganAdmin(admin.ModelAdmin):
    list_display = ('id', 'slogan', 'created_at',)
    search_fields = ('slogan',)
    ordering = ('created_at',)

And, almost done ...

I added slogans, to the installed_apps section of the settings.py.

And I get, for free, all CRUD functionality. That's just a lot of magic you have to love.

I'll see what I can do with Python and Django in the coming weeks. But this is a start.