Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
HorseRecords - Andy Ide
HorseRecords@andyide40 on Twitterdjangoandy.comdjango-autocomplete-lightdjango-qAssets in Django without losing your hair by Jacob Kaplan-Moss @Pycon US 2019Support the ShowThis podcast does not have any ads or sponsors. To support the show, please consider purchasing a book, signing up for Button, or reading the Django News newsletter. -
django-upgrade Mega Release 1.11.0
I just released version 1.11.0 of django-upgrade, a tool for automatically upgrading your Django project code. This release contains a lot of new features and fixes, thanks to new contributors including those at the Djangocon Europe sprints. Let’s look at the top changes. New admin.site.register() fixer Originally the Django admin required you to first define a ModelAdmin class, and then later register Model classes to use it with admin.site.register(): from django.contrib import admin class MyCustomAdmin(admin.ModelAdmin): ... admin.site.register(MyModel1, MyCustomAdmin) admin.site.register(MyModel2, MyCustomAdmin) With this format, the register() calls can become quite separated from the admin classes. In more complicated scenarios, you might also miss exactly which Model classes are registered to an admin class. To solve these problems, Django 1.7 (September 2014!) added the admin.register() class decorator: from django.contrib import admin @admin.register(MyModel1, MyModel2) class MyCustomAdmin(admin.ModelAdmin): ... django-upgrade can now automatically upgrade from the first form to the second: from django.contrib import admin +@admin.register(MyModel1, MyModel2) class MyCustomAdmin(admin.ModelAdmin): ... -admin.site.register(MyModel1, MyCustomAdmin) -admin.site.register(MyModel2, MyCustomAdmin) This works with various forms of admin.site.register() calls, and with GIS admin aliases as well. Thanks to Thibaut Decombe for contributing this feature. New @admin.action() and @admin.display() fixers The Django admin has two special kinds of functions: actions and display functions. … -
About my proposal for the Django Core Sprints 🌅
The story of how the proposal to organize sprints on the Django core was born and how I proposed it during the past DjangoCon US 2022 in San Diego to various components of the Django community. -
My Django active developers Sprints proposal 🌅
The story of how the proposal to organize sprints on the Django active developers was born and how I proposed it during the past DjangoCon US 2022 in San Diego to various components of the Django community. -
Performance "Seasons" Are Useless — Use Anniversary Reviews Instead
Stop doing performance reviews based on the calendar year. Instead, schedule performance reviews around each person’s individual calendar — a year after they join the team, switch roles, get promoted, etc. -
Migrating to a Custom User Model Mid-project in Django
This article explains step-by-step how to migrate to a custom User model mid-project in Django. -
How to Handle Django Forms within Modal Dialogs
I like django-crispy-forms. You can use it for stylish uniform HTML forms with Bootstrap, TailwindCSS, or even your custom template pack. But when it comes to custom widgets and dynamic form handling, it was always a challenge. Recently I discovered htmx. It's a JavaScript framework that handles Ajax communication based on custom HTML attributes. In this article, I will explore how you can use django-crispy-forms with htmx to provide a form with server-side validation in a modal dialog. The setup For this experiment, I will be using these PyPI packages: Django - my beloved Python web framework.django-crispy-forms - library for stylized forms.crispy-bootstrap5 - Bootstrap 5 template pack for django-crispy-forms.django-htmx - some handy htmx helpers for Django projects. Also, I will use the CDN versions of Bootstrap5 and htmx. The form I decided to add some crispy style to the login form by extending Django's authentication form and attaching a crispy helper to it. from django.contrib.auth.forms import AuthenticationFormfrom crispy_forms.helper import FormHelperfrom crispy_forms.layout import Layoutfrom crispy_bootstrap5 import bootstrap5class LoginForm(AuthenticationForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_tag = False self.helper.include_media = False self.helper.layout = Layout( bootstrap5.FloatingField("username", autocomplete="username"), bootstrap5.FloatingField("password", autocomplete="current-password"), ) Here I set form_tag to False to skip the <form> … -
Django News - Django Developers Survey 2022 Last Call! - Oct 21st 2022
News Django Developers Survey 2022 - Last Call The Django Developers Survey 2022 closes Sunday, October 23rd. Please ensure you have filled it out and encourage others to do the same. jetbrains.com 2023 DSF Board Nominations Applications for the 2023 Django Software Foundation Board of Directors are now open until November 4th. Please consider running. djangoproject.com Nominations for 2022 Malcolm Tredinnick Memorial Prize The Malcolm Tredinnick Memorial Prize is a monetary prize, awarded annually, to the person who best exemplifies the spirit of Malcolm’s work - someone who welcomes, supports, and nurtures newcomers; freely gives feedback and assistance to others, and helps to grow the community. Nominations are open until Thursday, October 30th, 2022, AoE. djangoproject.com PyCon US 2023 Launches! PyCon US is back in Salt Lake City in 2023. blogspot.com Sponsored Ad Django for Beginners/APIs/Professionals Level up your Django knowledge with Django for Beginners, Django for APIs, or Django for Professionals. Sample chapters are available to preview for free. learndjango.com Articles 12 Factor App Revisited An illustrated 10 years later look at The Twelve-Factor App methodology and how it holds up today. architecturenotes.co Future Proofing SQL with Carefully Placed Errors A look at maintaining forward/backward compatibility not just with … -
Migrate PostgreSQL ID’s from serial to identity after upgrading to Django 4.1
The Django 4.1 release notes feature this short, innocent-looking note: On PostgreSQL, AutoField, BigAutoField, and SmallAutoField are now created as identity columns rather than serial columns with sequences. In this post, we’ll expand on what this means, why you might want to update existing columns from serial types to identity columns, and a management command to update them. Serial versus identity What are “identity” and “serial” columns? Well, basically they’re PostgreSQL’s two different ways to create auto-incrementing ID columns. Originally PostgreSQL only had serial types, used like: CREATE TABLE example ( id serial NOT NULL PRIMARY KEY ); These serial types are not true data types. Instead, it’s a shorthand that creates a column and a sequence for its default value. PostgreSQL 10 (Oct 2017) added support for SQL-standard identity columns, used like: CREATE TABLE example ( id integer NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY ); (Documented under CREATE TABLE, search for “identity” on the page.) As the syntax shows, the column has a data type, integer, and then “identity” behaviour on top of that. There is an associated sequence for generating values, but PostgreSQL manages this internally. For regular usage, there is not much difference between … -
The Intersection of Tenure and Seniority
Patterns of short tenure are normal at the beginning of a career, but are more of a red flag in more senior roles. Here’s why. -
How To Add Sentry - Building SaaS with Python and Django #148
In this episode, I switched my error management system from Rollbar to Sentry and walked through some of Sentry’s features. -
Django News - Django Unicorn Chat - Oct 14th 2022
News Django Developers Survey 2022 Please take a moment to fill out the Django Developers Survey 2022 and encourage others in the community to do the same. It really helps guide the direction of the framework. jetbrains.com Last call for DjangoCon US tickets Last call for DjangoCon US 2022 tickets. Join us virtually this Monday, October 17th, and save 10% on all ticket types. If you are there in person, say hi to William and Jeff. ti.to Sponsored Ad Django for Beginners/APIs/Professionals Level up your Django knowledge with Django for Beginners, Django for APIs, or Django for Professionals. Sample chapters are available to preview for free. learndjango.com Articles Building a Realtime Chat App with Django Channels and WebSockets Learn how to build a realtime chat app using Django Channels and WebSockets. honeybadger.io DjangoTricks: How to Rename a Django App A good guide to renaming existing apps which is a very common occurrence. blogspot.com To Do List - Part 1: Installing Django - CTRL Z Blog The first in a very beginner-friendly 8-part series on building a Django To Do app. ctrlzblog.com Python Type Hints - Lambdas don’t support type hints, but that’s okay A look at how Mypy can infer … -
How to Fix the set-output GitHub Actions Deprecation Warning
If you have a GitHub Actions workflow that sets an output using echo ::set-output key=value, you have started to see an unhelpful deprecation warning. Here’s how to fix it. -
Writing With Copilot
On using Copilot as a writing assistant, and my complex feelings about the ethics of doing so. -
When Is Short Tenure a Red Flag?
A pattern of short tenure – multiple short jobs over a small period of time – can be a red flag, but necessarily. I’ll dig into short tenure in this article. What’s “short”? What’s a “pattern”? When you’re thinking of switching jobs, when and how should your tenure factor into the decision? For hiring managers, when is it reasonable to be concerned about job tenure, and what should we do when we become concerned? -
Is this a parable about software development?
You tell me. -
How to implement a “dry run mode” for data imports in Django
In data import processes it’s often useful to have a “dry run” mode, that runs through the process but doesn’t actually save the data. This can allow you to check for validity and gather statistics, such as how many records already exist in the database. In this post, we’ll look at how to implement a dry run mode in Django by using a database transaction and rolling it back. Example use case Take these models: from django.db import models class Author(models.Model): name = models.TextField() class Meta: constraints = [ models.UniqueConstraint( name="%(app_label)s_%(class)s_name_unique", fields=["name"], ) ] class Book(models.Model): title = models.TextField() author = models.ForeignKey(Author, on_delete=models.DO_NOTHING) class Meta: constraints = [ models.UniqueConstraint( name="%(app_label)s_%(class)s_title_author_unique", fields=["title", "author"], ) ] Imagine you have the mission to write a management command to import data from a CSV into Author and Book. The CSV lists book titles alongside author names: Title,Author The Very Hungry Caterpillar,Eric Carle A Message to Garcia,Elbert Hubbard To Kill a Mockingbird,Harper Lee The import process should avoid creating duplicate authors and books that already exist in the database. After it’s done, it should list the number of books and authors imported. In dry run mode, the command should still output the counts, but not … -
Django Unicorn - Adam Hill
Django UnicornColtranedjango-fbvminestroneAdam's DjangoCon EU 2021 Talkdevmarks.ioalldjango.compython-utils.comLocality of Behavior Support the ShowThis podcast does not have any ads or sponsors. To support the show, please consider purchasing a book, signing up for Button, or reading the Django News newsletter. -
Role Title Terminology
In my writing about hiring and management, I often talk about role titles – terms like “manager”, “director”, “executive”, and so forth. I’ve found that many readers find the precise definitions of these terms confusing. So here’s a glossary of the terms I use when I’m talking about job titles. -
Deploying a Django App to Dokku on a DigitalOcean Droplet
This tutorial looks at how to deploy a Django application to Dokku on a DigitalOcean droplet. -
How to count the most common lines in a file
tl;dr `sort myfile.log | uniq -c | sort -n -r` -
Django News - Django security releases: 4.1.2, 4.0.8, and 3.2.16 - Oct 7th 2022
News Django security releases issued: 4.1.2, 4.0.8, and 3.2.16 This release addresses a potential denial-of-service vulnerability in internationalized URLs. As always, updating to the latest version of Django is the best security policy. djangoproject.com Last call for DjangoCon US In-Person tickets DjangoCon US 2022 is less than two weeks away! IN-PERSON ticket sales end Friday, October 7th. We also have online tickets if you can’t make it in person this year. Django News subscribers save 10% off all ticket types. djangoproject.com Django Developers Survey 2022 The survey is still live. Please take a moment to fill it out and encourage others in the community to do the same. It helps guide the future development of Django! jetbrains.com Sponsored Ad Django for Beginners/APIs/Professionals Level up your Django knowledge with Django for Beginners, Django for APIs, or Django for Professionals. Sample chapters are available to preview for free. learndjango.com Events What’s New in Wagtail is back! Register for live demos on October 11th and 12th of Wagtail 4.0 and its many new features: redesigned page editor, enhanced accessibility, new features for snippets, global settings for multi-site installations, and more! wagtail.org Articles How to Safely Pass Data to JavaScript in a Django Template … -
Heroku Stack Upgrade - Building SaaS with Python and Django #147
In this episode, I did some upgrades. We upgraded the app to the latest Heroku stack, upgraded htmx to the latest version, then worked on a small feature to add an empty state to a page when there is no useful data to display. -
How to Safely Pass Data to JavaScript in a Django Template
You want to pass your data from your Django view to JavaScript, in your template. And, you want to do it securely, with no risk of accidentally allowing malicious code injection. Great, this is the post for you! We’re going to look at the problems with templating JavaScript, then two techniques: Data attributes for simple values json_script for complex values And finally, some other options that I don’t recommend. Let’s go! Templating JavaScript don’t work Many developers try templating inline <script> tags directly: {# DON’T DO THIS #} <script> const username = "{{ username }}"; </script> I recommend you never do this! This doesn’t generally work, since Django performs HTML-escaping on the value. For example, if username was "Adam <3", the output would be: <script> const username = "Adam &lt;3"; </script> This would mean displaying the username incorrectly. Additionally, it’s super dangerous if you template non-string variables, or use JavaScript template literals (JavaScript’s f-strings that use backticks). For example, take this template: {# DON’T DO THIS #} <script> const greeting = `Hi {{ username }}`; </script> A malicious value can use a backtick to end the literal, and then add arbitrary JavaScript. For example, if username was: a`; document.body.appendChild(document.createElement(`script`)).src = … -
Accepting Files
Full show notes are available at https://www.mattlayman.com/django-riffs/17.