Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Numbers in Translatable Strings
Sentences in websites like "You've got 1 messages." or "Messages you've got: 5" sound unnatural and not human-friendly. But the GNU gettext tool used with Django for translations has an option to define different pluralization depending on the number which goes together with the counted noun. Things get even more interesting with certain languages which have not just singular and plural like English, German, French, or Spanish, but more plural forms or just a single one. Tell me the background Let's talk about grammar. Most languages have two plural forms for counted elements: one for singular, like "1 thing", and one for plural, like "n things". However, certain languages have either just one form for singular and plural, or multiple plural forms depending on the number of elements that go with them. For example, my mother tongue Lithuanian is a Baltic language coming from Indo-European language family keeping archaic features from ancient Sanskrit. Lithuanian has 3 plural forms. When one counts apples in Lithuanian, they say "1 obuolys", "2-9 obuoliai", "10-20 obuolių", "21 obuolys", "22-29 obuoliai", "30 obuolių", "31 obuolys", "32-39 obuoliai", etc. The second most widespread language on the web after English is Russian. Russian is an Eastern Slavic … -
How to Create Django Data Migrations
Data Migration is a very convenient way to change the data in the database in conjunction with changes in the schema. They work like a regular schema migration. Django keep track of dependencies, order of execution and if the application already applied a given data migration or not. A common use case of data migrations is when we need to introduce new fields that are non-nullable. Or when we are creating a new field to store a cached count of something, so we can create the new field and add the initial count. In this post we are going to explore a simple example that you can very easily extend and modify for your needs. Data Migrations Let’s suppose we have an app named blog, which is installed in our project’s INSTALLED_APPS. The blog have the following model definition: blog/models.py from django.db import models class Post(models.Model): title = models.CharField(max_length=255) date = models.DateTimeField(auto_now_add=True) content = models.TextField() def __str__(self): return self.title The application is already using this Post model; it’s already in production and there are plenty of data stored in the database. id title date content 1 How to Render Django Form Manually 2017-09-26 11:01:20.547000 […] 2 How to Use Celery … -
A Complete Beginner's Guide to Django - Part 4
Introduction This tutorial is going to be all about Django’s authentication system. We are going to implement the whole thing: registration, login, logout, password reset, and password change. You are also going to get a brief introduction on how to protect some views from non-authorized users and how to access the information of the logged in user. In the next section, you will find a few wireframes of authentication-related pages that we are going to implement in this tutorial. After that, you will find an initial setup of a new Django app. So far we have been working on an app named boards. But all the authentication related stuff can live in a different app, so to achieve a better organization of the code. Wireframes We have to update the wireframes of the application. First, we are going to add new options for the top menu. If the user is not authenticated, we should have two buttons: sign up and log in. Figure 1: Top menu for not authenticated users. If the user is authenticated, we should instead display their names along with a dropdown menu with three options: my account, change password and log out. Figure 2: Top menu … -
Evennia 0.7 released
As of today Evennia 0.7 is officially out! A big thank you to all collaborators that have helped with code and testing along the way!Here is the hefty forum post that details how you migrate to Evennia 0.7. Evennia 0.7 comes with a range changes and updates (these are just the ones merged from the latest devel branch, a lot more has happened since 0.6 that were already in master): EvMenu formatting functions now part of class - EvMenu no longer accepts formatting functions as inputs, these are now part of the EvMenu class. To override the formatting of EvMenu nodes you should now override EvMenu and replace the format method you want. This brings EvMenu more in line with other services in Evennia, all of which are built around overriding.Scripts are now valid message senders - Also Scripts can now act as "sender" of a Msg, for example to a Channel or a player.Prefix-ignoring - All default commands are now renamed without their @-prefixes. Both @examine, +examine or examine will now all point to the same command. You can customize which prefixes Evennia simply ignores when searching for a command. The mechanic is clever though - if you create … -
A Complete Beginner's Guide to Django - Part 3
Introduction In this tutorial, we are going to dive deep into two fundamental concepts: URLs and Forms. In the process, we are going to explore many other concepts like creating reusable templates and installing third-party libraries. We are also going to write plenty of unit tests. If you are following this tutorial series since the first part, coding your project and following the tutorial step by step, you may need to update your models.py before starting: boards/models.py class Topic(models.Model): # other fields... # Add `auto_now_add=True` to the `last_updated` field last_updated = models.DateTimeField(auto_now_add=True) class Post(models.Model): # other fields... # Add `null=True` to the `updated_by` field updated_by = models.ForeignKey(User, null=True, related_name='+') Now run the commands with the virtualenv activated: python manage.py makemigrations python manage.py migrate Or if you prefer to use my source code as a starting point, you can grab it on GitHub. The current state of the project can be found under the release tag v0.2-lw. The link below will take you to the right place: https://github.com/sibtc/django-beginners-guide/tree/v0.2-lw The development will follow from here. URLs Proceeding with the development of our application, now we have to implement a new page to list all the topics that belong to a given Board. … -
Blue/Green Deployments on Kubernetes
> For those that want to dive right in, I have put up a tutorial and some sample manifests on github. Check it out at https://github.com/IanLewis /kubernetes-bluegreen-deployment-tutorial Kubernetes has a really awesome built-in feature called Deployments. Deployments come with the ability to do rolling updates of containers when you update your application to a new version. Rolling updates are a great way to update applications because your app uses about the same amount of resources during an update as it does when not updating, all with minimal impact to performance and availability. [...] -
Blue/Green Deployments on Kubernetes
> For those that want to dive right in, I have put up a tutorial and some > sample manifests on github. Check it out at > https://github.com/IanLewis/kubernetes-bluegreen-deployment-tutorial Kubernetes has a really awesome built-in feature called Deployments. Deployments come with the ability to do rolling updates of containers when you update your application to a new version. Rolling updates are a great way to update applications because your app uses about the same amount of resources during an update as it does when not updating, all with minimal impact to performance and availabilit[...] -
Multitenancy: juggling customer data in Django
Suppose you want to build a new SaaS (Software as a Service) application. Suppose your application will store sensitive data from your customers. What is the best way to guarantee the isolation of the data and make sure information from one client does not leak to the other? The answer to that is: it depends. It depends on the number of customers y -
cache_memoize - a pretty decent cache decorator for Django
This is something that's grown up organically when working on Mozilla Symbol Server. It has served me very well and perhaps it's worth extracting into its own lib. Usage Basically, you are probably used to this in Django: from django.core.cache import cache def compute_something(user, special=False): cache_key = 'meatycomputation:{}:special={}'.format(user.id, special) value = cache.get(cache_key) if value is None: value = _call_the_meat(user.id, special) # some really slow function cache.set(cache_key, value, 60 * 5) return value Here's instead how you can do exactly the same with cache_memoize: from wherever.decorators import cache_memoize @cache_memoize(60 * 5) def compute_something(user, special=False): return _call_the_meat(user.id, special) # some really slow function Cache invalidation If you ever need to do non-trivial caching you know it's important to be able to invalidate the cache. Usually, to be able to do that you need to involved in how the cache key was created. Consider our two examples above, here's first the common thing to do: def save_user(user): do_something_that_will_need_to_cache_invalidate(user) cache_key = 'meatycomputation:{}:special={}'.format(user.id, False) cache.delete(cache_key) # And when it was special=True cache_key = 'meatycomputation:{}:special={}'.format(user.id, True) cache.delete(cache_key) This works but it involves repeating the code that generates the cache key. You could extract that into its own function of course. Here's how you do it with … -
A Complete Beginner's Guide to Django - Part 2
Introduction Welcome to the second part of our Django Tutorial! In the previous lesson, we installed everything that we needed. Hopefully, you are all setup with Python 3.6 installed and Django 1.11 running inside a Virtual Environment. We already created the project we are going to play around. In this lesson, we are going to keep writing code in the same project. In the next section, we are going to discuss a little bit about the project we are going to develop, so to give you some context. Then after that, you are going to learn all the Django fundamentals: models, admin, views, templates, and URLs. Hands on! Web Board Project I don’t know about you, but personally, I learn much more by seeing practical examples and code snippets. For me, it’s difficult to process a concept where in the examples you read Class A and Class B, or when I see the classical foo(bar) examples. I don’t want to do that with you. So, before we get into the fun part, playing with models, views, and everything. Let’s just take a moment and discuss very briefly about this project we are going to develop. If you already have experience … -
Tecken loadtesting
My project over the summer, here at Mozilla, has been a project called Mozilla Symbol Server. It's a web service to upload C++ symbol files, downloading C++ symbol files and symbolicating C++ crash stacktraces using said uploaded C++ symbol files. It went into production last week which was fun but there's still lots of work to do on adding beyond-parity features and more optimizations. What Is Mozilla Symbol Server? The code name for this project is Tecken and it's written in Python (Django, Gunicorn) and uses PostgreSQL, Redis and Celery. The frontend is entirely static and developed (almost) as a separate project within. The frontend is written in React (using create-react-app and react-router). Everything is run as Docker containers. And if you ask me more details about how it's configured/deployed I'm afraid I have to defer to the awesome Mozilla CloudOps team. One the challenges is that the downloading part is that it needs to be fast and handle high traffic. Today I did some load testing and managed to start 14 concurrent clients that bombarded our staging server with realistic HTTPS GET queries based on log files. It's actually 8 + 4 + 2 concurrent clients. 7 of them … -
Mozilla Symbol Server (aka. Tecken) load testing
(Thanks Miles Crabil not only for being an awesome Ops person but also for reviewing this blog post!) My project over the summer, here at Mozilla, has been a project called Mozilla Symbol Server. It's a web service that uploads C++ symbol files, downloads C++ symbol files and symbolicates C++ crash stacktraces. It went into production last week which was fun but there's still lots of work to do on adding beyond-parity features and more optimizations. What Is Mozilla Symbol Server? The code name for this project is Tecken and it's written in Python (Django, Gunicorn) and uses PostgreSQL, Redis and Celery. The frontend is entirely static and developed (almost) as a separate project within. The frontend is written in React (using create-react-app and react-router). Everything is run as Docker containers. And if you ask me more details about how it's configured/deployed I'm afraid I have to defer to the awesome Mozilla CloudOps team. One the challenges I faces developing Tecken is that symbol downloads need to be fast to handle high volumes of traffic. Today I did some load testing on our stage deployment and managed to start 14 concurrent clients that bombarded our staging server with realistic HTTPS … -
A Complete Beginner's Guide to Django - Part 1
Introduction I’m starting today a new tutorial series about the Django fundamentals. It’s a complete beginner’s guide to start learning Django. The material is divided in 7 parts. We’re going to explore all the basic concepts in great detail, from installation, preparation of the development environment, models, views, templates, urls to more advanced topics such as migrations, testing and deployment. I wanted to do something different. A tutorial that would be easy to follow, informative and fun to read. That was when I came up with the idea to create some comics along the text to illustrate some concepts and scenarios. I hope you enjoy the reading! But before we start… Back when I worked as a substitute professor in a university, I used to teach a introduction to web development discipline for the newcomer students in the Computer Science course. And I would always start a new classes with this Confucius quote: So, hands on! Don’t just read the tutorials. Let’s do it together! You will learn much more by doing and practicing. Installation The first thing we need to do is install some programs in our machine so to be able to start playing with Django. The basic … -
Moving to Relay in Django backend
Today I want to talk a little bit more about my next step in developing a GraphQL application. This step is connected with moving backend so it understands Relay. What exactly is Realy? As documentation of Relay suggests - it's framework for working with external data in React. What does it … -
Going to Technical Events is Awesome: A DjangoCon Experience
We just got back from DjangoCon US! It was quite a marathon for us, as you can check here and yet quite fruitful. Along with the talks we got to give, it was awesome to meet new people and reunite with old friends. From our blog, you’d guess that we really enjoy conferences. We incentivize collaborators to attend them. Attending conferences is a gr -
Going to Technical Events Can be Awesome: A DjangoCon Experience
Going to Technical Events Can be Awesome: A DjangoCon Experience -
How going to technical events can be awesome: A DjangoCon Experience
-
post-DjangoCon US
-
Advanced Django File Handling
Advanced Django File Handling Modern Django's file handling capabilities go well beyond what's covered in the tutorial. By customizing the handlers that Django uses, you can do things pretty much any way you want. -
Renaming Django's Auth User and App
Now that Evennia's devel branch (what will become Evennia 0.7) is slowly approaching completion, I thought I'd try to document an aspect of it that probably took me the longest to figure out. One change in Evennia 0.7 is that the Django model named "Player" changes name to "Account". Over time it has become clear that the old name didn't properly reflected the intention of the model. Sounds like a simple change, right? Well, it was not.Briefly on migrationsFirst some background. A Django migration is a small Python file sitting in migrations/ sub folders throughout Evennia. A migration describes how our database schema changes over time, so as we change or update fields or add new features we add new migrations to describe how to go from the old to the new state. You apply them with the `evennia migrate` command we sometimes ask you to run. If we did not supply migrations, anyone with an existing Evennia database would have to either start from scratch or manually go in and tweak their database to match every upstream change we did.Each migration file has a sequential number, like migration_name.0002.py etc. Migrations will run in order but each migration can also … -
What are Kubernetes Pods Anyway?
Recently I saw a tweet from the awesome Amy Codes (I really hope that's her real name) about Kubernetes Pods: > You know why containers in a pod are always scheduled together? It's cuz they're nested containers. Mind. Blown. > > -- Amy Codes (@TheAmyCode) August 21, 2017 While it wasn't 100% accurate (Containers aren't really a thing. We'll get to that in a bit) it did point out the fact that Pods are amazing things. It's worth taking a look at Pods and containers in general and learn what they actually are. The Kubernetes documentation on Pods provides the best and most complete[...] -
What are Kubernetes Pods Anyway?
Recently I saw a tweet from the awesome Amy Codes (I really hope that's her real name) about Kubernetes Pods: > You know why containers in a pod are always scheduled together? It's cuz > they're nested containers. > > Mind. Blown. > > -- Amy Codes (@TheAmyCode) August 21, 2017 While it wasn't 100% accurate (Containers aren't really a thing. We'll get to that in a bit) it did point out the fact that Pods are amazing things. It's worth taking a look at Pods and containers in general and learn what they actually are. The Kubernetes documentation on Pods provides the best and most comp[...] -
Silvrback Rolls Out New Look
-
DjangoCon 2017 Recap
Mid-August brought travel to Spokane for several Caktus staff members attending DjangoCon 2017. As a Django shop, we were proud to sponsor and attend the event for the eighth year. Meeting and Greeting We always look forward to booth time as an opportunity to catch up with fellow Djangonauts and make new connections. Caktus was represented by a team of six this year: Charlotte M, Karen, Mark, Julie, Tobias, and Whitney. We also had new swag and a GoPro Session to give away. Our lucky winner was Vicky. Congratulations! This year we also had a special giveaway: one free ticket to the conference, donated to DjangoGirls Spokane. The winner, Toya, attended DjangoCon for the first time. We hope she had fun! Toya's a lucky #djangogirl. She won a ticket to @djangocon from @CaktusGroup and a book from keynote speaker @limedaring 🦄 pic.twitter.com/LxvSxPjW0S— Django Girls Spokane (@DjangoGirlsSpo) August 12, 2017 Top Talks Our technical staff learned a lot from attending the other talks presented during the conference. Their favorite talks included the keynote by Alicia Carr, The Denormalized Query Engine Design Pattern, and The Power and Responsibility of Unicode Adoption. Awesome inspiring keynote by @Fineblkwoman about how you can learn to … -
CFE CLI
The Coding for Entrepreneurs C...