Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django: Flush out test flakiness by randomly ordering QuerySets
Sometimes code depends on the order of a QuerySet whilst not specifying an order. This can lead to random, flaky test failures because databases can return rows in any order when none is specified. The problem is made worse by some databases, notably PostgreSQL, which nearly always return rows in insert order, but occasionally use a different order when a table has had recent deletions. For example, take this test: from django.test import TestCase from example.models import Book from example.tasks import import_books class ImportBooksTests(TestCase): def test_success(self): import_books("sutherland.csv") books = Book.objects.all() assert books[0].name == "Transport for Humans" assert books[1].name == "Alchemy" The assertion block depends on the order of books. Unless the model has a Meta.ordering attribute, the database can return rows in any order. This test will occasionally, even rarely, fail due to a mismatch of books[0].name. The simplest fix is to specify an ordering: from django.test import TestCase from example.models import Book from example.tasks import import_books class ImportBooksTests(TestCase): def test_success(self): import_books("sutherland.csv") - books = Book.objects.all() + books = Book.objects.order_by("id") assert books[0].name == "Transport for Humans" assert books[1].name == "Alchemy" David Winterbottom’s post Patterns of flakey Python tests lists unspecified QuerySet ordering as a known flakiness-inducing pattern. He gave a … -
Django: A version of json_script for pre-serialized JSON strings
Django’s json_script template filter is a convenient and safe way to pass a larger amount of data to JavaScript. I covered it in my post last year How to Safely Pass Data to JavaScript in a Django Template. I found an interesting use case for json_script in my client Silvr’s project. The view had a pandas DataFrame that needed passing through the template to a chart-drawing JavaScript function. The default json_script wouldn’t work with pandas’ JSON output, so I created a custom version. pandas provides DataFrame.to_json() for converting a DataFrame to a JSON string. This method is convenient but its output is still not safe against HTML injection—it needs the escaping that json_script performs. But json_script only accepts an object to turn into a JSON string, and then escape - it cannot operate on a pre-serialized JSON string. You could add the escaping with a chain of: DataFrame.to_json to convert to a JSON string json.loads() to unserialize the result json_script on the result, to re-serialize and escape the result But the repeated serialization is wasteful and would take non-negligible time with large data. Rather than do that, I made a custom template filter that was a modified copy of json_script … -
Weeknotes (2023 week 26)
Weeknotes (2023 week 26)Releases I released updates to a few of my packages; I have continued converting packages to hatchling and ruff while doing that. New releases in the last two weeks include: django-tree-queries 0.15: Added a new function, .without_tree_fields() to the queryset which can be used to avoid the .with_tree_fields(False) boolean trap warning. feincms3-cookiecontrol 1.3.1: This small update allows replacing the feincms3 noembed.com oEmbed code using other libraries such as micawber which support a wider range of URLs while still gating the embed behind users’ explicit consent. feincms3-downloads 0.5.3: Updated translations. django-ckeditor 6.6.1: Updated the bundled CKEditor 4 and merged a pull request adding better integration with Django admin’s dark mode. django-js-asset 2.1: Just basic maintainability and packaging updates. The JS() implementation itself is untouched since February 2022. html-sanitizer 2.0: Not really a backwards incompatible change (at least not according to the tests); I just wanted to avoid 1.10 and go directly to 2.0 this time. GitHub projects We are using GitHub project boards more and more. It definitely isn’t the most versatile way of managing projects but it sort-of hits the sweet spot for us. [I’m mostly happy with it, and it seems to me that applying the … -
Django News - Wagtail Roadmap - Jun 30th 2023
News Introducing the Wagtail Roadmap Curious what's next for Wagtail? There's a roadmap for that. wagtail.org Deprecation of bdist_egg uploads to PyPI PyPI will stop accepting .egg uploads starting August 1, 2023. If you maintain and packages on PyPI, you'll want to know this. pypi.org Updates to Django Updates to Django From Django Review and Triage Team Member Sarah Boyce... Last week we had 10 pull requests merged into Django by 8 different contributors - including 1 first time contributor! Congratulations to Yaser Amiri for having their first commit merged into Django - welcome on board! Now, from Django 5.0, @sensitive_variables and @sensitive_post_parameters supports async functions! Are you excited to contribute but not know where to start? Maybe you're interested in migrations? You could add logging of applied/unapplied migrations #24800 and then you'd be perfect to add contributor documentation for django.db.migrations #24989! Look forward to welcoming you on board! github.com Sponsored Link Learn More About our Django Services At HackSoft, we offer expert Django software development, consultation and support, to help you build robust and scalable software. hacksoft.io Articles COUNTing is hard: A tale of types in SQL and Django The tale of an ORM bug that took several hours … -
Accounts and Email - Building SaaS #164
In this episode, I planned to do the work of sending email prompts for the journal to users. Along the path, we realized that the Account model was missing, so I stopped to build that out before we could proceed. By the end of the stream, we had a working background job that would send email and was 100% unit tested. -
Accounts and Email - Building SaaS with Python and Django #164
In this episode, I planned to do the work of sending email prompts for the journal to users. Along the path, we realized that the Account model was missing, so I stopped to build that out before we could proceed. By the end of the stream, we had a working background job that would send email and was 100% unit tested. -
Two Ways to Turbo-Charge tox
No, it’s not (just) run-parallel – let’s cut the local tox runtime by 75%! -
Django News - Bringing Locality of Behavior to Django - Jun 23rd 2023
News The 2023 PSF Board Election is Open! In order to vote in this election, individuals must be a Contributing, Managing, Supporting, or Fellow member as of June 15, 2023, and have confirmed their intention to vote by June 19, 2023. blogspot.com Wagtail 5.0.2 release notes New features and bug fixes in the latest Wagtail version. wagtail.org Announcing Our New Security Developer in Residence! The Python Software Foundation now has a security developer in residence. blogspot.com Updates to Django Updates to Django From Django Review and Triage Team Member Sarah Boyce... Last week we had 13 pull requests merged into Django by 10 different contributors - including 2 first time contributors! Congratulations to Olivier Le Thanh Duong and Ashwin Dharne for having their first commits merged into Django - welcome on board! This time filtering support was added to GIS aggregate functions, and an offset value was added to StepValueValidator! You will be able to use both of these features in 5.0. Do you want to add something into Django 5.0? Why don't you update assertContains and assertInHTML to output a haystack on failure #34657? Look forward to welcoming you on board! github.com Sponsored Link Learn More About our Django … -
First Major Model - Building SaaS #163
In this episode, we got to work on the core modeling for the application. I started by adding some visualization tooling to see the models in the system, then got to modeling of the primary Entry model that will be used throughout the app. Along the way, we set up the Django admin and did some automated testing. -
First Major Model - Building SaaS with Python and Django #163
In this episode, we got to work on the core modeling for the application. I started by adding some visualization tooling to see the models in the system, then got to modeling of the primary Entry model that will be used throughout the app. Along the way, we set up the Django admin and did some automated testing. -
How to Learn Django (Replay)
Learning Python via Django Considered HarmfulDjango Girls TutorialDjango for BeginnersInstall Python3 on Mac/Windows/Linuxawesome-django repodjango-vanilla-viewsClassy Class-Based Views siteDjango Deployment ChecklistGroupsDjango Users Google GroupStack OverflowSubreddits: LearningDjango and DjangoDjango MeetupsSHAMELESS PLUGSLearnDjango.comCarlton's website Noumenal -
2023 Python Software Foundation Board Nomination
My self-nomination statement for the 2023 Python Software Foundation (PSF) Board Election -
2023 Python Software Foundation Board Nomination
My self-nomination statement for the 2023 Python Software Foundation (PSF) Board Election -
Python Community News Interview
Interview I gave to the “Python Community News” channel regarding my self-nomination for the 2023 Python Software Foundation (PSF) Board of Directors elections. -
FeinCMS is a dead end (but feincms3 is not)
FeinCMS is a dead end (but feincms3 is not) I wouldn’t encourage people to start new sites with FeinCMS. Five years ago I wrote that FeinCMS is used in a few flagship projects which we’re still actively developing, which means that FeinCMS won’t be going away for years to come. That’s still true but less and less so. We’re actively moving away from FeinCMS where we can, mostly towards feincms3 and django-content-editor. FeinCMS lives on in django-content-editor and feincms3; not only in spirit but also in (code) history, since django-content-editor contains the whole history of FeinCMS up to and including the beginning of 2016. The implementation of FeinCMS is too expensive to clean up without breaking backwards compatibility. I still wish I had pursued an incremental way back then which would have allowed us to evolve old projects to the current best way of doing things (tm), but it didn’t happen and I’m not shedding too many tears about that since I’m quite happy with where we’re at today. That basically means that I won’t put any effort into bringing FeinCMS and django-content-editor closer together. I haven’t spent much time on that anyway but now my mind is made up … -
Streaming Protocols continued... RTMP, MMS
Audio streaming protocols explained with rtmp and mms in depth. We develop audio streaming services and we will setup your internet radio. -
Django - Database access optimization
Django - Database access optimization. Write the best query to reduce the time and improve the application performance. using select_related and prefetch_related will form sql query with joins. In some cases It will reduce extra queries to the database. -
What's great about Django girls to inspire women into programming
Django girls is a non-profit organization, that helps women to learn Django programming language and to inspire them into programming. -
Python development environment on windows
Python development environment on windows in an easy and simple way -
Streaming protocols ogg, mp3, aac
Audio streaming protocols ogg, mp3 and aac explained in simple and advanced methods. We develop internet radio stations and we can do it for you. -
Dynamically Adding Google Maps with Marker In Django
Dynamically Adding Google Maps with Marker In Django -
Linux, managing child processes executing concurrently
Concurrent processing is complicated, it’s better to avoid it when possible, but when there is a priority for faster execution or there is a need to have multiple functionalities(programs) simultaneously we have to go for it. Using ampersand(&) symbol we can run processes in background or subshell, this way they run concurrently. -
How to use gulpjs to Minify css, js and convert less, scss to css
Use gulpjs to Minify css, js and convert less, scss to css -
Python + Upsolver: Simplified Realtime Data Workflows
One of the powerful things about Python is its ability to connect disparate tools into one common integrated development experience. In this talk, we’ll explore how to create and run a near real-time pipeline where we consume events from a Kafka topic and transform the data before landing them in the lake, using Upsolver through our Python SDK. In this way, we get exactly-once processing, strong ordering and automatic schema evolution out of the box thanks to the powerful Upsolver engine, but without having to switch to a different UI and building in SQL only. -
Python + Upsolver: Simplified Realtime Data Workflows
One of the powerful things about Python is its ability to connect disparate tools into one common integrated development experience. In this talk, we’ll explore how to create and run a near real-time pipeline where we consume events from a Kafka topic and transform the data before landing them in the lake, using Upsolver through our Python SDK. In this way, we get exactly-once processing, strong ordering and automatic schema evolution out of the box thanks to the powerful Upsolver engine, but without having to switch to a different UI and building in SQL only.