Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
7 Conferences We’re Looking Forward To
Above: The Internet Summit in Raleigh is one of the local conferences we recommend attending. (Photo by Ian Huckabee.) At Caktus, we strongly believe in professional development and continued learning. We encourage our talented team to stay up to date with industry trends and technologies. During 2018, Cakti attended a number of conferences around the country. Below is a list (in alphabetical order) of the ones we found the most helpful, practical, and interesting. We look forward to attending these conferences again, and if you get the chance, we highly recommend that you check them out as well. All Things Open Recommended by Account Executive Tim Scales Next Conference Location: Raleigh Next Conference Date: October 13 - 15, 2019 All Things Open is a celebration and exploration of open source technology and its impact. Topics range from nuts and bolts sessions on database design and OSS languages to higher-level explorations of current trends like machine learning with Python and practical blockchain applications. The annual conference is heavily publicized in the open source community, of which Caktus is an active member. All Things Open attracts open source thought leaders from across industries, and it’s a valuable learning experience for both non-technical … -
Container Runtimes Part 4: Kubernetes Container Runtimes & CRI
This is the fourth and last part in a four part series on container runtimes. It's been a while since part 1, but in that post I gave an overview of container runtimes and discussed the differences between low-level and high- level runtimes. In part 2 I went into detail on low-level container runtimes and built a simple low-level runtime. In part 3 I went up the stack and wrote about high-level container runtimes. Kubernetes runtimes are high-level container runtimes that support the Container Runtime Interface (CRI). CRI was introduced in Kubernetes 1.5 and acts as a bridge between the [...] -
Container Runtimes Part 4: Kubernetes Container Runtimes & CRI
This is the fourth and last part in a four part series on container runtimes. It's been a while since part 1, but in that post I gave an overview of container runtimes and discussed the differences between low-level and high- level runtimes. In part 2 I went into detail on low-level container runtimes and built a simple low-level runtime. In part 3 I went up the stack and wrote about high-level container runtimes. Kubernetes runtimes are high-level container runtimes that support the Container Runtime Interface (CRI). CRI was introduced in Kubernetes 1.5 and acts as a bridge between the [...] -
Django Quiz 2016
I realized I’ve posted the 2017 and 2018 editions of the London Django Meetup December quizzes on my blog, but forgot to post the first one in 2016. So here it is reproduced below, if you’d like to play at home or scroll through to the answers to pick up on some more Django trivia. Part 1: Multiple Choice 1. In which city in Kansas was Django conceived? Newton Lawrence Pittsburg 2. In what year was Django first released? 1999 2001 2005 3. Where was Djangocon EU 2016 held? Cardiff Budapest Bucharest 4. When does Python 2.7 stop being supported? 1 Jan 2018 2020 April 12 2020 5. Which version of Django will drop Python 2 compatibility? 1.12 2.0 2.1 6. Which of these popular sites does not run on Django? Instagram Slideshare Bitbucket Disqus 7. What is i18n short for? Internationalization International Code 18 Internal operation 8. Which official Django project offers websocket and asynchronous task support? Inputs Transmissions Channels 9. What does SQL stand for? Standard Query Language Structured Query Language SQL’s a Query Language Part 2: Freeform answers 1. Which database servers does Django core include backends for? One point each, but minus one for each wrong. … -
How to add buttons to ModelAdmin Index View in Wagtail CMS
By default, every object in ModelAdmin's Index View of Wagtail CMS gets two buttons: Edit and Delete. What if we want to add more buttons? Is that possible in Wagtail? My answer is yes, and it's easy! Follow me! Let's add a "View" button Let's assume ... Read now -
Dagger 2: How to Understand and Use Components and Modules
Dagger is a great tool for dependency injection (DI). It does most of the job in compile time, making applications smaller and faster and dependency resolving safer. The post Dagger 2: How to Understand and Use Components and Modules appeared first on Distillery. -
variable_cache_control - Django view decorator to set max_age in runtime
tl;dr; If you use the django.views.decorators.cache.cache_control decorator, consider this one instead to change the max_age depending on the request. I had/have a Django view function that looks something like this: @cache_control(publiic=True, max_age=60 * 60) def home(request, oc=None, page=1): ... But, that number 60 * 60 I really needed it to be different depending on the request parameters. For example, that oc=None, if that's not None I know the page's Cache-Control header can and should be different. So I wrote this decorator: from django.utils.cache import patch_cache_control def variable_cache_control(**kwargs): """Same as django.views.decorators.cache.cache_control except this one will allow the `max_age` parameter be a callable. """ def _cache_controller(viewfunc): @functools.wraps(viewfunc) def _cache_controlled(request, *args, **kw): response = viewfunc(request, *args, **kw) copied = kwargs if kwargs.get("max_age") and callable(kwargs["max_age"]): max_age = kwargs["max_age"](request, *args, **kw) # Can't re-use, have to create a shallow clone. copied = dict(kwargs, max_age=max_age) patch_cache_control(response, **copied) return response return _cache_controlled return _cache_controller Now, I can do this instead: def _best_max_age(req, oc=None, **kwargs): max_age = 60 * 60 if oc: max_age *= 10 return max_age @variable_cache_control(publiic=True, max_age=_best_max_age) def home(request, oc=None, page=1): ... I hope it inspires. -
PyRoma 2019
The first of the PyRoma (Python User Group of Rome, Italy) periodic meetings in 2019 -
A Salmagundi of Django Alpha Announcements
Reading the Django 2.2 alpha announcement, the phrase “salmagundi of new features” stood out to me. I had to look up “salmagundi” in Wiktionary, where it is defined as: A food consisting of chopped meat and pickled herring, with oil, vinegar, pepper, and onions. Hence, any mixture of various ingredients; an olio or medley; a potpourri; a miscellany. So it basically means there is a mix of new features. This reminded me, didn’t Django 2.1 use another food related word for this - “smorgasboard”? Looking back at the previous alpha announcements, it turns out that a plethora of words have been used to describe the variety of features offered by each release. It seems the tradition started with version 1.7 - the 1.6 alpha announcement post refers simply to “new stuff”. I pulled the phrases, the individual “mix” words, and the post authors for all the announcement posts back to 1.7. I then checked the words against the word frequency list Peter Norvig provides in his article English Letter Frequency Counts, based upon Google Books data of the millions of English books Google have scanned. For reference, the most common word there is “the” with a frequency of 53,097,401,461 (see … -
The Future of Typography: An Introduction to Variable Fonts
Designers, imagine a world in which the number of fonts used on a website or app isn’t limited by load speed, or by the availability of styles in a font family. You’d no longer be limited to a few weights (light, regular, bold) and widths (condensed, regular, expanded). Instead, you could exercise a fine degree of control over all of these properties. The post The Future of Typography: An Introduction to Variable Fonts appeared first on Distillery. -
How to Dockerize Django and Postgres
Docker is an invaluable tool that makes things like setting up your local development environment, continuous integration, and deployment a breeze. Docker is good to set up early on for any application, but it is never too late. With the help of Docker Compose, we are going to set up a Django application to install … Continue reading How to Dockerize Django and Postgres The post How to Dockerize Django and Postgres appeared first on concise coder. -
How to Dockerize Django and Postgres
Docker is an invaluable tool that makes things like setting up your local development environment, continuous integration, and deployment a breeze. Docker is good to set up early on for any application, but it is never too late. With the help of Docker Compose, we are going to set up a Django application to install … Continue reading How to Dockerize Django and Postgres The post How to Dockerize Django and Postgres appeared first on concise coder. -
How to Create PDF Documents with Django in 2019
If you've read my Web Development with Django Cookbook, you might remember a recipe for creating PDF documents using Pisa xhtml2pdf. Well, this library does its job, but it supports only a subset of HTML and CSS features. For example, for multi-column layouts, you have to use tables, like it's 1994. I needed some fresh and flexible option to generate donation receipts for the donation platform www.make-impact.org and reports for the strategic planner 1st things 1st I have been building. After a quick research I found another much more suitable library. It's called WeasyPrint. In this article, I will tell you how to use it with Django and what's valuable in it. Features WeasyPrint uses HTML and CSS 2.1 to create pixel-perfect, or let's rather say point-perfect, PDF documents. WeasyPrint doesn't use WebKit or Gecko but has its own rendering engine. As a proof that it works correctly, it passes the famous among web developers Acid2 test which was created back in the days before HTML5 to check how compatible browsers are with CSS 2 standards. All supported features and unsupported exceptions are listed in the documentation. But my absolute favorites are these: Layouts with floated elements. You don't have … -
Django Tips #7: Function-Based Views vs Class-Based Views
An overview of the history and pros/cons of each approach. -
How to Use Django Bulk Inserts for Greater Efficiency
It's been awhile since we last discussed bulk inserts on the Caktus blog. The idea is simple: if you have an application that needs to insert a lot of data into a Django model — for example a background task that processes a CSV file (or some other text file) — it pays to "chunk" those updates to the database so that multiple records are created through a single database operation. This reduces the total number of round-trips to the database, something my colleague Dan Poirier discussed in more detail in the post linked above. Today, we use Django's Model.objects.bulk_create() regularly to help speed up operations that insert a lot of data into a database. One of those projects involves processing a spreadsheet with multiple tabs, each of which might contain thousands or even tens of thousands of records, some of which might correspond to multiple model classes. We also need to validate the data in the spreadsheet and return errors to the user as quickly as possible, so structuring the process efficiently helps to improve the overall user experience. While it's great to have support for bulk inserts directly in Django's ORM, the ORM does not provide much assistance … -
Customizing Django REST API Serializers
Adding extra fields to Serializers # serializers.py from rest_framework import serializers from test_app.models import Product class ProductSerializer(serializers.Serializer): product_id = serializers.IntegerField() product = serializers.SerializerMethodField('get_product_name') def get_product_name(self, obj): if obj.get("product_id"): obj_product = Product.objects.filter(id=obj.get("product_id")).first() if obj_product: return obj_product.name return None # API views.py from rest_framework.decorators import api_view from rest_framework.response import Response from rest_framework import status from test_app.serializers import ProductsSerializer @api_view(['GET']) def list_products(request): response_data = {} response_data["data"] = ProductSerializer( [{"program": i} for i in [1, 2, 3]], many=True ).data return Response(response_data, status=status.HTTP_200_OK) Passing extra arguments to Serializer Class in Django Rest Framework Suppose we have searlizer called 'CollegeStudentsSerializer' which should return all students, branches details of a logged-in user college # serializers.py from rest_framework import serializers from test_app.models import Student, Branch class StudentSerializer(serializers.ModelSerializer): class Meta: model = Student fields = ['id', 'first_name', 'last_name', 'branch'] class BranchSerializer(serializers.ModelSerializer): class Meta: model = Branch fields = ['id', 'name', 'code'] class CollegeDetailsSerializer(serializers.Serializer): students = serializers.SerializerMethodField('get_students') branches = serializers.SerializerMethodField('get_branches') def __init__(self, *args, **kwargs): context = kwargs.pop("context") self.college_id = context.get('college_id') super(CollegeDetailsSerializer, self).__init__(*args, **kwargs) def get_students(self, obj): return StudentSerializer( Student.objects.filter(college_id=self.college_id), many=True ).data def get_branches(self, obj): return BranchSerializer( Branch.objects.filter(college_id=self.college_id), many=True ).data # API views.py from rest_framework.decorators import api_view from rest_framework.response import Response from rest_framework import status from test_app.serializers import CollegeDetailsSerializer @api_view(['GET']) def … -
7 Awesome Augmented Reality Solutions
Augmented reality, also known as AR, is increasingly everywhere. Businesses across industries are turning to augmented reality app development to help them create new ways to engage their customers. Educators are using AR to develop new ways of teaching, and medical professionals are using it to transform the way they approach treatment. People of all ages and backgrounds are trying out the built-in AR functionalities of their smartphones. The post 7 Awesome Augmented Reality Solutions appeared first on Distillery. -
Marginal Gain #1: Make Common Tasks Easy
Marginal gains are minor improvements that are relatively easy to make. A single marginal gain does not have a meaningful effect, but several can aggregate into significant progress. I first read about this concept in James Clear’s Atomic Habits, and was inspired to apply this philosophy to software development. For a better understanding of what … Continue reading Marginal Gain #1: Make Common Tasks Easy The post Marginal Gain #1: Make Common Tasks Easy appeared first on concise coder. -
Marginal Gain #1: Make Common Tasks Easy
Marginal gains are minor improvements that are relatively easy to make. A single marginal gain does not have a meaningful effect, but several can aggregate into significant progress. I first read about this concept in James Clear’s Atomic Habits, and was inspired to apply this philosophy to software development. For a better understanding of what … Continue reading Marginal Gain #1: Make Common Tasks Easy The post Marginal Gain #1: Make Common Tasks Easy appeared first on concise coder. -
Distillery Makes the Entrepreneur 360TM for the Second Year in a Row!
Achieving success in business is no easy task. Sustaining that success is even harder. That’s why we’re excited to share another milestone marking sustained success for Distillery. For the second year in a row, we’ve been honored on the Entrepreneur 360! The post Distillery Makes the Entrepreneur 360TM for the Second Year in a Row! appeared first on Distillery. -
How to Use Date Picker with Django
In this tutorial we are going to explore three date/datetime pickers options that you can easily use in a Django project. We are going to explore how to do it manually first, then how to set up a custom widget and finally how to use a third-party Django app with support to datetime pickers. Introduction Tempus Dominus Bootstrap 4 Direct Usage Custom Widget XDSoft DateTimePicker Direct Usage Custom Widget Fengyuan Chen’s Datepicker Direct Usage Custom Widget Conclusions Introduction The implementation of a date picker is mostly done on the front-end. The key part of the implementation is to assure Django will receive the date input value in the correct format, and also that Django will be able to reproduce the format when rendering a form with initial data. We can also use custom widgets to provide a deeper integration between the front-end and back-end and also to promote better reuse throughout a project. In the next sections we are going to explore following date pickers: Tempus Dominus Bootstrap 4 Docs Source XDSoft DateTimePicker Docs Source Fengyuan Chen’s Datepicker Docs Source Tempus Dominus Bootstrap 4 Docs Source This is a great JavaScript library and it integrate well with Bootstrap 4. The … -
Year in Review (2018)
An overview of 2018 and looking ahead to 2019. -
Into 2019!
A new year has come around and it's time to both look back at the old and onward to the future of Evennia, the Python MUD creation system! Last year Last year saw the release of Evennia 0.8. This version of Evennia changes some fundamental aspects of the server infrastructure so that the server can truly run in daemon mode as you would expect (no more running it in a GnuScreen session if you want to see logging to the terminal). It also adds the new Online Creation System, which lets builders create and define prototypes using a menu system as well as big improvements in the web client, such as multiple window-panes (allows the user to assign text to different windows to keep their client uncluttered) as well as plenty of fixes and features to help ease life for the Evennia developer. Thanks again to everyone who helped out and contributed to the release of Evennia 0.8!On a personal note, I spoke about Evennia at PyCon Sweden this December, which was fun. I might put up my talk and make a more detailed blog post about that in the future, but my talk got a surprising amount of attention and … -
Top 14 Pros of Using Django for Web Development
Django is one of the top frameworks for web development, but why is it so popular among developers and business owners? Let’s review the reasons why so many applications and features are being developed with Django. 1. Django is simple Django’s documentation is exemplary. It was initially launched with high-quality docs, and they are still maintained at the same level, which makes it easy to use. More than that, one of Django’s main purposes is to simplify the development process: it covers the basics, so you can focus on the more unique and/or complex features of your project. 2. Django works on Python The framework is based on Python — a high-level, dynamic, and interpreted programming language, well-loved by developers. Although it’s hard to find a language that can cover most programming tasks and problems, Python is a great choice for many of them. It’s one of the most popular languages of 2018, competing with C/++ and Java. Python is: Portable. Your code can be ported to many platforms, from PC and Linux to PlayStation. Multi-paradigm. It supports object-oriented programing, which is a simple way to code, as well as imperative programming. More interactive than most other languages. It resembles … -
How to Implement Grouped Model Choice Field
The Django forms API have two field types to work with multiple options: ChoiceField and ModelChoiceField. Both use select input as the default widget and they work in a similar way, except that ModelChoiceField is designed to handle QuerySets and work with foreign key relationships. A basic implementation using a ChoiceField would be: class ExpenseForm(forms.Form): CHOICES = ( (11, 'Credit Card'), (12, 'Student Loans'), (13, 'Taxes'), (21, 'Books'), (22, 'Games'), (31, 'Groceries'), (32, 'Restaurants'), ) amount = forms.DecimalField() date = forms.DateField() category = forms.ChoiceField(choices=CHOICES) Grouped Choice Field You can also organize the choices in groups to generate the <optgroup> tags like this: class ExpenseForm(forms.Form): CHOICES = ( ('Debt', ( (11, 'Credit Card'), (12, 'Student Loans'), (13, 'Taxes'), )), ('Entertainment', ( (21, 'Books'), (22, 'Games'), )), ('Everyday', ( (31, 'Groceries'), (32, 'Restaurants'), )), ) amount = forms.DecimalField() date = forms.DateField() category = forms.ChoiceField(choices=CHOICES) Grouped Model Choice Field When you are using a ModelChoiceField unfortunately there is no built-in solution. Recently I found a nice solution on Django’s ticket tracker, where someone proposed adding an opt_group argument to the ModelChoiceField. While the discussion is still ongoing, Simon Charette proposed a really good solution. Let’s see how we can integrate it in our …