Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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. -
How To Add Sentry - Building SaaS #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. -
Heroku Stack Upgrade - Building SaaS #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. -
How to Rename a Django App
When I initially created my MVP (minimal viable product) for 1st things 1st, I considered the whole Django project to be about prioritization. After a few years, I realized that the Django project is about SaaS (software as a service), and prioritization is just a part of all functionalities necessary for a SaaS to function. I ended up needing to rename apps to have clean and better-organized code. Here is how I did that. 0. Get your code and database up to date Ensure you have the latest git pull and execute all database migrations. 1. Install django-rename-app Put django-rename-app into pip requirements and install them or just run: (venv)$ pip install django-rename-app Put the app into INSTALLED_APPS in your settings: INSTALLED_APPS = [ # … "django_rename_app", ] 2. Rename the app directories Rename the oldapp as newapp in your apps and templates. 3. Rename the app name occurrences in the code Rename the app in all your imports, relations, migrations, and template paths. You can do a global search for oldapp and then check case by case where you need to rename that term to newapp, and where not. 4. Run the management command rename_app Run the management command … -
How to Rename a Django App
When I initially created my MVP (minimal viable product) for 1st things 1st, I considered the whole Django project to be about prioritization. After a few years, I realized that the Django project is about SaaS (software as a service), and prioritization is just a part of all functionalities necessary for a SaaS to function. I ended up needing to rename apps to have clean and better-organized code. Here is how I did that. 0. Get your code and database up to date Ensure you have the latest git pull and execute all database migrations. 1. Install django-rename-app Put django-rename-app into pip requirements and install them or just run: (venv)$ pip install django-rename-app Put the app into INSTALLED_APPS in your settings: INSTALLED_APPS = [ # … "django_rename_app",] 2. Rename the app directories Rename the oldapp as newapp in your apps and templates. 3. Rename the app name occurrences in the code Rename the app in all your imports, relations, migrations, and template paths. You can do a global search for oldapp and then check case by case where you need to rename that term to newapp, and where not. 4. Run the management command rename_app Run the management command rename_app: … -
Episode 17 - Accepting Files
On this episode, we’re going to dig into file management. Unlike the static files that you create for the app yourself, you may want your app to accept files from your users. Profile pictures are a good example of user files. You’ll see how Django handles those kinds of files and how to deal with them safely. Listen at djangoriffs.com or with the player below. Last Episode On the last episode, we looked at how to manage settings on your Django site. -
Find the largest node_modules directories with bash
tl;dr; `fd -I -t d node_modules | rg -v 'node_modules/(\w|@)' | xargs du -sh | sort -hr -
Django News - Heroku Alternatives for Django Apps - Sep 30th 2022
News PyScript 2022.09.1 RC2 request for help The PyScript team is asking for help testing 2022.09.1 RC2. github.com Reminder: 2022 Django Developers Survey The survey will run until October 21st. Please take a moment to fill it out! After the survey is over, the aggregated results and anonymized raw data will be published. djangoproject.com Sponsored Ad Crunchy Bridge - Fully Managed Postgres as a Service crunchybridge.com Articles Heroku Alternatives for Python-based Applications Since Heroku is discontinuing its free tier November 28, 202 this article covers numerous Heroku alternatives and their pros and cons. testdriven.io Pytest for Beginners Not just for beginners, this article covers all the main parts of pytest, including parameterizing, fixtures, temporary files, and even monkeypatching. testdriven.io Django on K8s A 7-part series on Django and Kubernetes. dev.to Dockerize a Django, React, and Postgres application with Docker and docker-compose A relatively concise guide to Dockerizing a website with Django and React. dev.to Will Serving Real HTML Content Make A Website Faster? Let's Experiment! Some performance comparisons and stats compare rendering HTML and JS rendered websites. webpagetest.org Videos Preparing for Hacktoberfest with Phoebe Quincy Hacktoberfest kicks off on October 1st and lasts all month. Python Community News covers what … -
How to Develop Responsive HTML Email in Django
In this tutorial, I will talk about how to use Django-mjml to develop Responsive HTML Email in Django