Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
PyCon.de: vim your Python, Python your vim - Miroslav Šedivý
(One of my summaries of a talk at the 2017 PyCon.de conference). He has a nice simple keyboard layout. No weird key combinations. He started showing different keyboard layouts and started speaking fluently in en, de, sk, cs, fr, es, it, pl, sv, hu, eo, tr and explaining the various country's keyboard layouts. How do you manage all those languages one ONE keyboard with only ONE brain. Switching keyboards is no option. Charmaps are not easy. There used to be a key called the compose key. It was an actual key on older keyboards. You use compose + two or more keys after each other to get a é or an è, for instance. There's a x11 keymap for it. You can map various keys to function as the compose key. The printscreen key or the right control key or windows key, for instance. Another option is xcape, you can use one key (for instance the caps lock) as both the compose key and as another key. Keeping it pressed make it function as one, just pressing and releasing it quickly as the other. So: he uses the caps lock key as both ctrl and compose key. He then switched … -
PyCon.de: the borgbackup project - Thomas Waldmann
(One of my summaries of a talk at the 2017 PyCon.de conference). Borgbackup is 2.5 years old, but the code is older: is a fork of attic. Thomas discovered Attic after someone blogged about it. They forked it to get more collaboration and quicker releases. Borg backup is a backup tool. There are 1000 backup tools. So what's different? Borg is one you maybe actually would enjoy using. The features sound logical: simple, efficient, safe, secure. How borg sees this: Simple. Each backup is a full backup. Restore? Just do a FUSE mount. Easy pruning of old backups. Tooling: it is just borg, ssh and a shell. It is a single-file binary. There's good filesystem and OS support. There's good documentation. Efficient. It is very fast for unchanged files. Every backup is a full backup, but unchanged files don't need to be handled a second time. Chunk deduplication, sparse file support, flexible compression scheme. Compression is chunk-based, it doesn't compress the whole file at once. Safety. Checksums, transactions, filesystem syncing, atomic operations. Checkpoints while backing up. You can have off-site remote repositories. Secure. Authenticated encryption. There's nothing to see in the repo: borg doesn't trust the backup host, everything is … -
Five stories about the California Wildfires you probably missed
You’ve probably heard about the massive wildfires in Northern California. You probably know that they’re huge, that over 50 people have died, and that some wineries have burned. You might have seen some pictures. Unless you’ve been following closely, though, there’s a lot you’re missing. The vast majority of the reporting has lacked context, been overly sensationalistic, or has outright ignored deeper, more complex stories. It’s far deeper than a story about a natural disaster. -
How to Implement Django's Built In Password Management
Let's implement Django's built... -
Mercurial Mirror For Django 2.0 Branch
The first Beta was released today, so it seems a good day to start the mirror for the 2.0 branch of Django. For the record, main purposes of this mirror are: being a lightweight read-only repository to clone from for production servers hide the ugly git stuff behind a great mercurial interface The clone is […] -
Mailchimp Integration
The Mailchimp API is extensive... -
Automating Dokku Setup with AWS Managed Services
Dokku is a great little tool. It lets you set up your own virtual machine (VM) to facilitate quick and easy Heroku-like deployments through a git push command. Builds are fast, and updating environment variables is easy. The problem is that Dokku includes all of your services on a single instance. When you run your database on the Dokku instance, you risk losing it (and any data that's not yet backed up) should your VM suddenly fail. -
A Complete Beginner's Guide to Django - Part 7
Introduction Welcome to the last part of our tutorial series! In this tutorial, we are going to deploy our Django application to a production server. We are also going to configure an Email service and HTTPS certificates for our servers. At first, I thought about given an example using a Virtual Private Server (VPS), which is more generic and then using one Platform as a Service such as Heroku. But it was too much detail, so I ended up creating this tutorial focused on VPSs. Our project is live! If you want to check online before you go through the text, this is the application we are going to deploy: www.djangoboards.com. Version Control Version control is an extremely important topic in software development. Especially when working with teams and maintaining production code at the same time, several features are being developed in parallel. No matter if it’s a one developer project or a multiple developers project, every project should use version control. There are several options of version control systems out there. Perhaps because of the popularity of GitHub, Git become the de facto standard in version control. So if you are not familiar version control, Git is a good … -
PGDay.IT 2017
PGDay.IT is the Italian event dedicated to PostgreSQL, one of the most successful open-source projects. -
Kindle and ePub Now Available for Two Scoops of Django 1.11!
You asked for it, you got it. Two Scoops of Django 1.11 now comes in Kindle Mobi and ePub formats. If you've already purchased the PDF, you'll be receiving an email containing a new download link that adds the .mobi and .epub files. Otherwise, get yours at the following links: PDF/Kindle/ePub versions available here Amazon (Kindle only) -
Kindle and ePub Now Available for Two Scoops of Django 1.11!
You asked for it, you got it. Two Scoops of Django 1.11 now comes in Kindle Mobi and ePub formats. If you've already purchased the PDF, you'll be receiving an email containing a new download link that adds the .mobi and .epub files. Otherwise, get yours at the following links: PDF/Kindle/ePub versions available here Amazon (Kindle only) -
Kindle and ePub Now Available for Two Scoops of Django 1.11!
You asked for it, you got it. Two Scoops of Django 1.11 now comes in Kindle Mobi and ePub formats. If you've already purchased the PDF, you'll be receiving an email containing a new download link that adds the .mobi and .epub files. Otherwise, get yours at the following links: PDF/Kindle/ePub versions available here Amazon (Kindle only) -
Kindle and ePub Now Available for Two Scoops of Django 1.11!
You asked for it, you got it. Two Scoops of Django 1.11 now comes in Kindle Mobi and ePub formats. If you've already purchased the PDF, you'll be receiving an email containing a new download link that adds the .mobi and .epub files. Otherwise, get yours at the following links: PDF/Kindle/ePub versions available here Amazon (Kindle only) -
Simple or fancy UPSERT in PostgreSQL with Django
As of PostgreSQL 9.5 we have UPSERT support. Technically, it's ON CONFLICT, but it's basically a way to execute an UPDATE statement in case the INSERT triggers a conflict on some column value. By the way, here's a great blog post that demonstrates how to use ON CONFLICT. In this Django app I have a model that has a field called hash which has a unique=True index on it. What I want to do is either insert a row, or if the hash is already in there, it should increment the count and the modified_at timestamp instead. The Code(s) Here's the basic version in "pure Django ORM": if MissingSymbol.objects.filter(hash=hash_).exists(): MissingSymbol.objects.filter(hash=hash_).update( count=F('count') + 1, modified_at=timezone.now() ) else: MissingSymbol.objects.create( hash=hash_, symbol=symbol, debugid=debugid, filename=filename, code_file=code_file or None, code_id=code_id or None, ) Here's that same code rewritten in "pure SQL": from django.db import connection with connection.cursor() as cursor: cursor.execute(""" INSERT INTO download_missingsymbol ( hash, symbol, debugid, filename, code_file, code_id, count, created_at, modified_at ) VALUES ( %s, %s, %s, %s, %s, %s, 1, CLOCK_TIMESTAMP(), CLOCK_TIMESTAMP() ) ON CONFLICT (hash) DO UPDATE SET count = download_missingsymbol.count + 1, modified_at = CLOCK_TIMESTAMP() WHERE download_missingsymbol.hash = %s """, [ hash_, symbol, debugid, filename, code_file or None, code_id or … -
Disabling Error Emails in Django
One of Django's nice "batteries included" features is the ability to send emails when an error is encountered. This is a great feature for small sites where minor problems would otherwise go unnoticed. Once your site start getting lots of traffic, however, the feature turns into a liability. An error might fire off thousands of emails in rapid succession. Not only will this put extra load on your web servers, but you could also take down (or get banned from) your email server in the process. One of the first things you want to do when setting up a high-traffic Django site is replace the default error email functionality with an error reporting service like Sentry. Once you've got Sentry setup, what's the best way to disable error emails? Unfortunately, there isn't one simple answer. Let's dig into why... How does Django Send the Emails? First let's look at how Django sends those emails. If you look at the source, you'll find it is defined in the default logging config using standard Python logging: 'django': { 'handlers': ['console', 'mail_admins'], 'level': 'INFO', } As you can guess, the mail_admins handler is the one that does the work. It is defined as: … -
Disabling Error Emails in Django
One of Django's nice "batteries included" features is the ability to send emails when an error is encountered. This is a great feature for small sites where minor problems would otherwise go unnoticed. Once your site start getting lots of traffic, however, the feature turns into a liability. An error might fire off thousands of emails in rapid succession. Not only will this put extra load on your web servers, but you could also take down (or get banned from) your email server in the process. One of the first things you want to do when setting up a high-traffic Django site is replace the default error email functionality with an error reporting service like Sentry. Once you've got Sentry setup, what's the best way to disable error emails? Unfortunately, there isn't one simple answer. Let's dig into why... How does Django Send the Emails? First let's look at how Django sends those emails. If you look at the source, you'll find it is defined in the default logging config using standard Python logging: 'django': { 'handlers': ['console', 'mail_admins'], 'level': 'INFO', } As you can guess, the mail_admins handler is the one that does the work. It is defined as: … -
Custom Analytics with Django
Analytics can make our service... -
The Almighty Pause Container
When checking out the nodes of your Kubernetes cluster, you may have noticed some containers called "pause" running when you do a `docker ps` on the node. $ docker ps CONTAINER ID IMAGE COMMAND ... ... 3b45e983c859 gcr.io/google_containers/pause-amd64:3.0 "/pause" ... ... dbfc35b00062 gcr.io/google_containers/pause-amd64:3.0 "/pause" ... ... c4e998ec4d5d gcr.io/google_containers/pause-amd64:3.0 "/pause" ... ... 508102acf1e7 gcr.io/google_containers/pause-amd64:3.0 "/pause[...] -
The Almighty Pause Container
When checking out the nodes of your Kubernetes cluster, you may have noticed some containers called "pause" running when you do a `docker ps` on the node. $ docker ps CONTAINER ID IMAGE COMMAND ... ... 3b45e983c859 gcr.io/google_containers/pause-amd64:3.0 "/pause" ... ... dbfc35b00062 gcr.io/google_containers/pause-amd64:3.0 "/pause" ... ... c4e998ec4d5d gcr.io/google_containers/pause-amd64:3.0 "/pause" ... ... 508102acf1e7 gcr.io/google_containers/pause-amd64:3.0 "/[...] -
A Complete Beginner's Guide to Django - Part 6
Introduction Welcome to the sixth part of the tutorial series! In this tutorial, we are going to explore in great detail the Class-Based Views. We are also going to refactor some of the existing views so to take advantage of the built-in Generic Class-Based Views. There are many other topics that we are going to touch with this tutorial, such as how to work with pagination, how to work with Markdown and how to add a simple editor. We are also going to explore a built-in package called Humanize, which is used to give a “human touch” to the data. Alright, folks! Let’s implement some code. We have plenty of work to do today! Views Strategies At the end of the day, all Django views are functions. Even class-based views (CBV). Behind the scenes, it does all the magic and end-up returning a view function. Class-based views were introduced so to make it easier for developers to reuse and extend views. There are many benefits of using them, such as the extendability, the ability to use O.O. techniques such as multiple inheritances, the handling of HTTP methods are done in separate methods, rather than using conditional branching, and there are … -
Implement search with Django-haystack and Elasticsearch Part-1
Haystack works as a search plugin for Django. You can use different backends Elastic-search, Whose, Sorl, Xapian to search objects. All backends work with the same code. In this post, I am using elastic search as backend. Installation: pip install django-haystack Configuration: add haystack to installed apps INSTALLED_APPS=[ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', #add haystack here 'haystack', 'books' ] Settings: Add back-end settings for the haystack. HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', 'URL': 'http://127.0.0.1:9200/', 'INDEX_NAME': 'haystack_books', }, } Above settings for elastic search. Add signal processor for the haystack. This signal will update objects in … -
How to Create a Custom Django User Model
Django's built-in User model a... -
The Simple Power of Django Validators
# The Simple Power of Django V... -
Understanding Django Permissions And Groups
Permissions: Actually permissions are of 2 types: 1.Model level permissions 2.object level permissions If you want to give permissions on all cars, then Model-level is appropriate, but if you Django to give permissions on a per-car basis you want Object-level. You may need both, and this isn't a problem as we'll see. For Model permissions, Django will create permissions in the form 'appname.permissionname_modelname' for each model. If you have an app called 'drivers' with the Car model then one permission would be 'drivers.delete_car'. The permissions that Django automatically creates will be create, change, and delete.Read permission is not included in CRUD operation.Django decided to change CRUD's 'update' to 'change' for some reason. You can use the metaclass to add more permissions to a model.: class Book( models.Model ): # model stuff here class Meta: permissions = ( ( "read_book", "Can read book" ), ) Permissions is a set of tuples, where the tuple items are the permission as described above and a description of that permission. Finally, to check permissions, you can use has_perm: obj.has_perm( 'drivers.read_car' ) Where obj … -
Overriding Django Model behaviour with Proxy Model
The main Usage of a proxy model is to override the main functionality of existing Model. It is a type of model inheritance without creating a new table in Database. It always query on original model with overridden methods or managers. You can query, delete, edit, create etc on Proxy model but the effects will be on the original model. You can define models as a proxy just by adding proxy = True in Meta class of model. # Original Model class Employee(models.Model): EmployeeType = ( ("D", "Developer"), ("M", "Manager"), ) name = models.CharField(max_length=55) type = models.CharField(choices=EmployeeType, max_length=1, default='D') def __str__(self): return self.name # Model manager to use in Proxy model class ManagerEmpManager(models.Manager): def get_queryset(self): return super(ManagerEmpManager, self).get_queryset().filter( type='M') def create(self, **kwargs): kwargs.update({'type': 'M'}) return super(ManagerEmpManager, self).create(**kwargs) # Proxy Model class ManagerEmployee(Employee): objects = ManagerEmpManager() class Meta: proxy = True In ManagerEmployee I have overridden create method to set type …