Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
"Create Table As Select" in Django
A discussion recently came up on django-developers mailing list about how to build the SQL query CREATE TABLE ... AS SELECT (CTAS) with Django’s ORM. This statement and its cousin INSERT ... SELECT are useful for re-shaping data inside your database, using SELECT queries. They can be useful for building aggregate tables from complicated, slow queries, as a way of imitating materialized views on databases that don’t support them. Django doesn’t support these at current, but I found it’s not hard to implement using some Django ORM internals, and have an example function below. (Support might have changed by the time you’re reading this - check the linked mailing list thread!) Example Use Case For example, you might have a widget_summary table for analytics purposes built with a SELECT from your widget table joined with flimflams. You can then regularly rebuild the table with that CTAS query. We do this in a transaction on databases with transactional DDL (PostgreSQL, SQLite). Start a transaction, drop the table, recreate it with CTAS, and commit. On databases without transactional DDL, we need a temporary table. Create the table with a new name, hot-swap it in place with the atomic RENAME, then drop the … -
Improving Page Speed with Incremental Loading
Summary: you can use django-include-by-ajax to improve the performance and usability of your website by forcing some parts of the Django website page to be loaded and shown before other parts of the page. Web browsers load and render traditional HTML pages from top to down, from left to right and as a developer you have little control over what will be shown first, second, and last. However, sometimes you need a different loading sequence to improve user experience and usability. Let's examine a couple of cases when it is advantageous to have primary content showing up immediately and secondary content loading in a moment. Case 1. Above the Fold vs. Below the Fold People want speed. 47% of visitors expect the website to be loaded in less than 2 seconds. If the website takes more than 3 seconds to show up, it's a big chance, that you will lose 40% of visitors. If you sell something on your website, every one-second delay causes 7% fewer visitors becoming buyers. One technique to improve the perception of the speed of the website is to display the visible part of the screen as soon as possible, and then load the rest of … -
Improving Page Speed with Incremental Loading
Summary: you can use django-include-by-ajax to improve the performance and usability of your website by forcing some parts of the Django website page to be loaded and shown before other parts of the page. Web browsers load and render traditional HTML pages from top to down, from left to right and as a developer you have little control over what will be shown first, second, and last. However, sometimes you need a different loading sequence to improve user experience and usability. Let's examine a couple of cases when it is advantageous to have primary content showing up immediately and secondary content loading in a moment. Case 1. Above the Fold vs. Below the Fold People want speed. 47% of visitors expect the website to be loaded in less than 2 seconds. If the website takes more than 3 seconds to show up, it's a big chance, that you will lose 40% of visitors. If you sell something on your website, every one-second delay causes 7% fewer visitors becoming buyers. One technique to improve the perception of the speed of the website is to display the visible part of the screen as soon as possible, and then load the rest of … -
How to Switch to a Custom Django User Model Mid-Project
The Django documentation recommends always starting your project with a custom user model (even if it's identical to Django's to begin with), to make it easier to customize later if you need to. But what are you supposed to do if you didn't see this when starting a project, or if you inherited a project without a custom user model and you need to add one? At Caktus, when Django first added support for a custom user model, we were still using South for migrations. Hard to believe! Nearly six years ago, I wrote a post about migrating to a custom user model that is, of course, largely obsolete now that Django has built-in support for database migrations. As such, I thought it would be helpful to put together a new post for anyone who needs to add a custom user model to their existing project on Django 2.0+. Background As of the time of this post, ticket #25313 is open in the Django ticket tracker for adding further documentation about this issue. This ticket includes some high-level steps to follow when moving to a custom user model, and I recommend familiarizing yourself with this first. As noted in the … -
How to Switch to a Custom Django User Model Mid-Project
The Django documentation recommends always starting your project with a custom user model (even if it's identical to Django's to begin with), to make it easier to customize later if you need to. But what are you supposed to do if you didn't see this when starting a project, or if you inherited a project without a custom user model and you need to add one? -
How to: Run Django using Docker and Docker Compose
Read the full article -
Steaming on, eating jam
Image credit: The SmithsonianIn the last few months, development of the upcoming Evennia 0.9 has been steaming on. Evennia is, as you may know, a Python library for creating text-based multiplayer games (MUDs, MUSH etc).But it's not all backend work! There is also some sweet game-jamming going on, I get to that at the end. Evennia progress towards Python3 The regular Evennia develop branch is now running completely in Python 3. Since we are using some new features of this Python release, we will be aiming for Python 3.7 as a minimum version once Evennia 0.9 goes stable. We will also use Django 2.1 and likely Twisted 19 - so we'll be pretty much up-to-date on all our main dependencies.Now, while the release of Evennia 0.9 is still some time away (there are a bunch of regular bug fixes and minor features that I want to get in there too (see the progress here on the github 0.9 project page), it's worth to consider how much work it'll be for you to migrate and if you should wait or jump in right now.If you are new, I still recommend you use regular master branch Evennia (using Python 2.7). This is … -
Congrats to Distillery Partner PubNub on $23M in Series D Funding!
Following its $23M Series D round of funding, global data stream network (DSN) PubNub has the funding it needs to achieve its next stage of growth. The post Congrats to Distillery Partner PubNub on $23M in Series D Funding! appeared first on Distillery. -
My questions for prospective employers (Director/VP roles)
Last time I was looking for a job, I wrote up a list of questions I wanted to ask prospective employees. I just ran across the list again, and figured I’d share. I was looking for a senior management role (Director/VP-level) in Engineering or Security, so the questions are sloped in that direction. Also note that I was in a fairly strong position; I didn’t need the a job immanently. So, I was able to ask fairly direct, challenging questions. -
Family Trip to Joshua Tree
We took a family trip to Joshua Tree National Park to see the spring wildflowers in bloom. Our daughter Uma loved the fresh air and sunshine. Here, Daniel and Uma enjoy the beautiful scenery of the giant boulders. -
Family Trip to Joshua Tree
We took a family trip to Joshua Tree National Park to see the spring wildflowers in bloom. Our daughter Uma loved the fresh air and sunshine. Here, Daniel and Uma enjoy the beautiful scenery of the giant boulders. -
Family Trip to Joshua Tree
We took a family trip to Joshua Tree National Park to see the spring wildflowers in bloom. Our daughter Uma loved the fresh air and sunshine. Here, Daniel and Uma enjoy the beautiful scenery of the giant boulders. -
Avoid Memory Issues with Django’s bulk_create
When inserting a large number of objects into the database with Django, your first thought should be to use bulk_create. It is much more efficient than calling create for each object, and it generally only results in a single query. However, when dealing with tens of thousands, hundreds of thousands, or even more objects, you … Continue reading Avoid Memory Issues with Django’s bulk_create The post Avoid Memory Issues with Django’s bulk_create appeared first on concise coder. -
Avoid Memory Issues with Django’s bulk_create
When inserting a large number of objects into the database with Django, your first thought should be to use bulk_create. It is much more efficient than calling create for each object, and it generally only results in a single query. However, when dealing with tens of thousands, hundreds of thousands, or even more objects, you … Continue reading Avoid Memory Issues with Django’s bulk_create The post Avoid Memory Issues with Django’s bulk_create appeared first on concise coder. -
React Hooks - A deeper dive featuring useContext and useReducer
This article looks at how React JS hooks can be used to make React applications and their state management clean and efficient. -
Distillery Is Now a Certified Google Cloud Technology Partner!
We couldn’t be happier to announce that Distillery has now been certified as a Google Cloud Technology Partner! You might even say we’re on cloud nine about it. The post Distillery Is Now a Certified Google Cloud Technology Partner! appeared first on Distillery. -
Jupyter Notebook Server with AWS EC2 and AWS VPC
# Create your VPC You need a ... -
Summaries of the Python meetup in Amsterdam
I've made notes again at the 2019-04-11 Amsterdam Python meetup in the byte office. Here are the summaries. Ethics in IT - Nick Groenen Computer systems are taking over the world. They're influencing everything. A lot of good has come out of this. But there's also a downside. We're talking (at meetups like this, for instance) mostly about tech, not about the people that build it or the people affected by it. Nick Groenen calls that an ethics problem. As an example, Uber's "greyball" that was originally written for a good purpose but that was later used to mislead governments. Same with Volkswagen's diesel emissions scandal: detecting when there's an official test and adjusting the motor parameters to seem more environmentally friendly. How ethical is it to work on something like that? The above examples are of big companies. But what about working for smaller companies? You have the same ethical challenges there. What are you doing with your logfiles? How much information do you mine about your customers? Do you give customers' data to your boss when he asks about it even though it isn't allowed by your privacy policy? And how do you treat new programmers? Is there … -
How to Score A+ for Security Headers on Your Django Website
This is a blog post version of the talk I gave at DjangoCon Europe 2019 on the 10th April. The web is an evolving platform with a lot of backwards compatibility concerns. New web security practices often come from a realization that an old feature has some flaw. Rather than break old websites by changing such features, there are a bunch of more secure behaviours to opt in to. You can do this by setting HTTP headers. Securityheaders.com is a tool run by security consultant Scott Helme to create a report on these security headers. It gives any URL a score from F to A+, which is a nice simple way of measuring your security posture. Though, like any automated report, it needs need some human interpretation to factor in context. (I’d also recommend the Mozilla Observatory security scanner, but I’m not using it here because it does way more than security headers.) As an example, Yahoo scores an A+ on Securityheaders.com: Whilst (at time of writing) Google scores a C: This is a guide on how to configure a typical Django web application to score that magic A+. You can beat Google, protect your users, and impress your boss, … -
5 Things to Keep in Mind When Designing Your Business Logo
When designing your logo, you should pay close attention from the very first step in the design process. After all, your logo says a lot about your business. The post 5 Things to Keep in Mind When Designing Your Business Logo appeared first on Distillery. -
How to Save Extra Data to a Django REST Framework Serializer
In this tutorial you are going to learn how to pass extra data to your serializer, before saving it to the database. Introduction Example Using APIView Example Using ViewSet Introduction When using regular Django forms, there is this common pattern where we save the form with commit=False and then pass some extra data to the instance before saving it to the database, like this: form = InvoiceForm(request.POST) if form.is_valid(): invoice = form.save(commit=False) invoice.user = request.user invoice.save() This is very useful because we can save the required information using only one database query and it also make it possible to handle not nullable columns that was not defined in the form. To simulate this pattern using a Django REST Framework serializer you can do something like this: serializer = InvoiceSerializer(data=request.data) if serializer.is_valid(): serializer.save(user=request.user) You can also pass several parameters at once: serializer = InvoiceSerializer(data=request.data) if serializer.is_valid(): serializer.save(user=request.user, date=timezone.now(), status='sent') Example Using APIView In this example I created an app named core. models.py from django.contrib.auth.models import User from django.db import models class Invoice(models.Model): SENT = 1 PAID = 2 VOID = 3 STATUS_CHOICES = ( (SENT, 'sent'), (PAID, 'paid'), (VOID, 'void'), ) user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='invoices') number = models.CharField(max_length=30) date = … -
IQ isn't enough to get hired
I’ve interviewed hundreds of people for technical roles, and a pattern has emerged. In general, we reject many more candidates for social skills than for technical competence. In fact, most technical interview funnels are arranged so that technical screens are earlier. This means that if you reach an interview, you’ve probably (mostly) passed the technical part, and are now being judged mostly on EQ. If you get rejected at this point, it’s probably because of social skills. -
Django versus Flask with Single File Applications
A lot of people pick Flask over Django because they believe it is simpler to start with. Indeed, the Flask front page includes an 8 line “hello world” application, whilst the Django default project has 172 lines in 5 files, and still doesn’t say “hello world”! (It does show you a welcome rocket and have a full admin interface though, both are pretty fun). It is also possible to make a single file “hello world” application in Django, although it’s probably something most Django developers haven’t seen done. It takes a bit more code than Flask, but it’s still quite understandable. Let’s take a look at the Flask and Django implementations and use them to compare the two frameworks. Application We’ll be using the simple “hello world” application from the Pallets page on Flask (plus a security fix). It has one page which gets a name from the URL or the default “world”, and returns that with a “hello” message. For example: In Flask Here is the code, 10 lines long, tested on Flask 1.0.2 and Python 3.7.2: (I added html.escape to the Flask example, to fix a security problem.) import html from flask import Flask, request app = Flask(__name__) … -
Bring Your Logo to Life: 20 Gorgeous Logo Animations to Inspire You
A good logo leaves a clear image of the product or company in viewers’ minds long after they’ve seen it. By adding motion that helps to tell a brand’s story, animated logos can be highly effective in making a lasting impression. The post Bring Your Logo to Life: 20 Gorgeous Logo Animations to Inspire You appeared first on Distillery. -
Goals aren't enough; you have to talk about performance, too
Craig recently wrote about his mixed opinions about OKRs. The crux of his argument, I think, is that communicating goals is the important thing, and that OKRs are a heavyweight tool (with limited success). I agree, somewhat; this post is a “yes, and”: OKRs (when done well) do one other important thing: force explicit conversations about performance. Talking about goals can be fairly easy compared to talking about performance. But talking about performance is a basic management responsibility, and unfortunately it’s frequently done poorly (if at all).