Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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). -
Essential PyCharm (Intellij) Plugins To Improve Productivity
As per 2019 JetBrains survery, PyCharm is the most widely used(36%) IDE for Python development. Eventhough PyCharm comes with lot of built in features, there are a lot of plugins available for PyCharm and other Intellij IDEs. In this article, we will see some plugins which will boost our productivity during development. Highlight Bracket Pair Instead of manually scanning where a bracket starts/ends, Highlight Bracket Pair will automatically hightlight the bracket pairs based on cursor position. Rainbow Brackets Highlight Bracket Pair will hightlight the bracket pair around the cursor. When there are multiple bracket pairs deeply nested, Rainbow Brackets will highlight matching bracket pairs with matching rainbow colors. Grep Console When running a django/flask server or any Python script which generates lot of output, it is hard to filter out required output on console. Grep Console can filter or highlight output based on specific conditions which makes it easier to debug the code. Save Actions Instead of manually optimizing imports or reformating code when changes are made, we can use Save Actions which will automatically run a set of actions on every file save. Key Promoter If you are new to PyCharm or an experienced user who is using mouse … -
What I Learned at PyCon Namibia 2019
I was at PyCon Namibia in Windhoek from the 19th to 21st of February, and had an amazing time! PyCon Namibia is one of the longest running PyCons in Africa, this being its fifth edition in as many years. I had the pleasure of being invited to join by Daniele Procida, after joining him at the first PyCon Ghana last summer. I couldn’t say no to another African Python adventure! (No mum, there weren’t any snakes.) I also had the great responsibility of delivering the final day keynote, on technologies that will be around in 21 years. There will be a blog post at some point, but if you want to read the slides they are on my GitHub. Outside of the conference I had great opportunities to see the country and socialize with my fellow Python developers. I joined a social day before the conference where some of the organizers gave us a tour of the Katutura area of Windhoek and a road trip around the country afterwards. Python Community Namibia is the world’s second least densely populated country, with a lot of desert and a population of 2.5 million. Comparing it to PyCon UK, the Python conference is … -
De-Google my life - Part 3 of ¯ (ツ)_/¯: Nextcloud & Collabora
Hello everyone! Welcome to the third post of my blogseries “De-Google my life”. If you haven’t read the other ones you definitely should! (Part 1, Part 2). Today we are moving forward with one of the most important apps I’m running on my servers: Nextcloud. A big part of my Google usage was Google Drive (and all it’s derivate apps). With Nextcloud I was looking to replace: Docs Drive Photos Contacts Calendar Notes Tasks More (?) I also wanted some new features, like connecting to a S3 bucket directly from my server and have a web interface to interact with it. The first step is to set up the server. I’m not going to explain that again, but if you want to read more about that, I explain it a bit better on the second post Nextcloud Installation For my Nextcloud installation I went straight to the official docker documentation and extracted this docker compose: version: '2' volumes: nextcloud: db: services: db: image: mariadb command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW restart: always volumes: - db:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=my_super_secure_root_password - MYSQL_PASSWORD=my_super_secure_password - MYSQL_DATABASE=nextcloud - MYSQL_USER=nextcloud app: image: nextcloud ports: - 8080:80 links: - db volumes: - nextcloud:/var/www/html restart: always Some mistakes were made I … -
De-Google my life - Part 3 of ¯ (ツ)_/¯: Nextcloud & Collabora
Hello everyone! Welcome to the third post of my blogseries “De-Google my life”. If you haven’t read the other ones you definitely should! (Part 1, Part 2). Today we are moving forward with one of the most important apps I’m running on my servers: Nextcloud. A big part of my Google usage was Google Drive (and all it’s derivate apps). With Nextcloud I was looking to replace: Docs Drive Photos Contacts Calendar Notes Tasks More (?) I also wanted some new features, like connecting to a S3 bucket directly from my server and have a web interface to interact with it. The first step is to set up the server. I’m not going to explain that again, but if you want to read more about that, I explain it a bit better on the second post Nextcloud Installation For my Nextcloud installation I went straight to the official docker documentation and extracted this docker compose: version: '2' volumes: nextcloud: db: services: db: image: mariadb command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW restart: always volumes: - db:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=my_super_secure_root_password - MYSQL_PASSWORD=my_super_secure_password - MYSQL_DATABASE=nextcloud - MYSQL_USER=nextcloud app: image: nextcloud ports: - 8080:80 links: - db volumes: - nextcloud:/var/www/html restart: always Some mistakes were made I … -
What is Django CRM and it’s advantages
Customer relationship management (CRM) is the combination of practices, strategies and technologies that companies use to manage and analyze customer interactions and data throughout the customer lifecycle, with the goal of improving customer service relationships and assisting in customer retention and driving sales growth. Importance of CRM Customer Relationship Management allows businesses to manage customer relationships including the data and information associated with the companies. The right CRM acts as a dashboard where you can manage your sales, marketing, customer service and support, tracking customers response, and assigning tasks to employees. A good CRM solution builds value by opening up vital communication channels and creating a common client-focused knowledge base. CRM system makes it easier for everyone inside your company to work together and share your ideas, strategies, plan of action and goals, that all comes together to keep your customers satisfied and loyal. Types of CRM: CRM systems are classified into two types On premise CRM system On demand CRM system On premise CRM system : Depending upon the company requirements they will design a basic CRM system with required modules and functionalities. Most probably small to mid level companies design their custom CRM system for their business … -
A Story Worth Telling: 10 Design Trends to Watch in 2019
Did you know that stock photos are passé, asymmetry is in, and accessibility is an increasing focus for designers? Find out which design trends we expect to see more of in 2019. The post A Story Worth Telling: 10 Design Trends to Watch in 2019 appeared first on Distillery. -
Quiet down 'faker' in pytests
Faker is a nice library for creating sample data for tests. No more company called "example company" and no more email address "something@example.org". No, you get readable random proper email addresses and company names and so. Handy in combination with factory_boy, which provides integration. Here's an example: from myproject import models import factory class PersonF(factory.DjangoModelFactory): class Meta: model = models.Person email = factory.Faker("email") name = factory.Faker("name") password = factory.Faker("password") class TeamF(factory.DjangoModelFactory): class Meta: model = models.Team name = factory.Faker("company") Problem I'm having is that, when running the tests with pytest, pytest helpfully reports all the logging when something goes wrong. Only, tests related to factory_boy/faker fill the log with locale-related messages: factory.py 97 DEBUG Looking for locale `en_US` in provider `faker.providers.address`. factory.py 111 DEBUG Provider `faker.providers.address` has been localized to `en_US`. factory.py 97 DEBUG Looking for locale `en_US` in provider `faker.providers.automotive`. factory.py 111 DEBUG Provider `faker.providers.automotive` has been localized to `en_US`. factory.py 97 DEBUG Looking for locale `en_US` in provider `faker.providers.bank`. Which makes it harder to spot the actual error. There's been a recent helpful change to faker, reducing those log messages from INFO to DEBUG. So fixing these extraneous messages was as simple as including these lines at the … -
De-Google my life - Part 2 of ¯ (ツ)_/¯: Servers and Emails
Hello everyone! Welcome to the second post of this blog series that aims to de-google my life as much as possible. If you haven’t read the first one, you should definitely check it out. On this delivery we’ll focus more on code and configurations so I promise you it won’t be as boring :) Servers configuration As I mentioned on the previous post, I’ll be using two servers that are going to be configured almost the same, so I’m going to explain it only one time. In order to host my servers I’m using DigitalOcean because I’m very used to their UI, their prices are excelent and they accept Paypal. If you haven’t yet, you should check them out. To start, I’m using their $5 server which at the time of this writing includes: Ubuntu 18.04 64 bits 1GB RAM 1 CPU 1000 GB of monthly transfers Installation On my first SSH to the server I perform basic tasks such as updating and upgrading the server: sudo apt update && sudo apt ugrade - y Then I install some essentials like Ubuntu Common Properties (used to add new repositories using add-apt-repository) NGINX, HTOP, GIT and Emacs, the best text editor … -
De-Google my life - Part 2 of ¯ (ツ)_/¯: Servers and Emails
Hello everyone! Welcome to the second post of this blog series that aims to de-google my life as much as possible. If you haven’t read the first one, you should definitely check it out. On this delivery we’ll focus more on code and configurations so I promise you it won’t be as boring :) Servers configuration As I mentioned on the previous post, I’ll be using two servers that are going to be configured almost the same, so I’m going to explain it only one time. In order to host my servers I’m using DigitalOcean because I’m very used to their UI, their prices are excelent and they accept Paypal. If you haven’t yet, you should check them out. To start, I’m using their $5 server which at the time of this writing includes: Ubuntu 18.04 64 bits 1GB RAM 1 CPU 1000 GB of monthly transfers Installation On my first SSH to the server I perform basic tasks such as updating and upgrading the server: sudo apt update && sudo apt ugrade - y Then I install some essentials like Ubuntu Common Properties (used to add new repositories using add-apt-repository) NGINX, HTOP, GIT and Emacs, the best text editor … -
Best way to count distinct indexed things in PostgreSQL
`SELECT COUNT(*) FROM (SELECT DISTINCT my_not_unique_indexed_column FROM my_table) t` -
Best way to count distinct indexed things in PostgreSQL
`SELECT COUNT(*) FROM (SELECT DISTINCT my_not_unique_indexed_column FROM my_table) t` -
Coding for Time Zones & Daylight Saving Time — Oh, the Horror
In this post, I review some reasons why it's really difficult to program correctly when using times, dates, time zones, and daylight saving time, and then I'll give some advice for working with them in Python and Django. Also, I'll go over why I hate daylight saving time (DST). TIME ZONES Let's start with some problems with time zones, because they're bad enough even before we consider DST, but they'll help us ease into it. Time Zones Shuffle Time zones are a human invention, and humans tend to change their minds, so time zones also change over time. Many parts of the world struggle with time changes. For example, let's look at the Pacific/Apia time zone, which is the time zone of the independent country of Samoa. Through December 29, 2011, it was -11 hours from Coordinated Universal Time (UTC). From December 31, 2011, Pacific/Apia became +13 hours from UTC. What happened on December 30, 2011? Well, it never happened in Samoa, because December 29, 23:59:59-11:00 is followed immediately by December 31, 0:00:00+13:00. Date Time Zone Date Time Zone 2011-12-29 23:59:59 UTC-11 2011-12-30 10:59:59 UTC 2018-12-31 00:00:00 UTC+13 2011-12-30 11:00:00 UTC That's an extreme example, but time zones change more … -
Backup & Load Live Heroku PostgreSQL Database to Local Django Project
I've used [Django fixtures](ht... -
Where to Learn Django in 2019
I quite often get asked for resources on where to learn Django. Here’s a list of the places I know! The Deep End First, a warning: there’s a lot of stuff to know. Learning Django with zero web or programming knowledge is diving in at the deep end. If you’ve never done anything like it, you’ll be learning about Python, databases, HTML, CSS, browsers, Git, Django, and more, all at the same time. I’d recommend knowing how to build a static website before attempting to learn Django. There are many ways to do this, for free tutorials check out W3Schools or Learn Web Development from Mozilla. But if you think you’re ready to begin, let’s continue. Written Tutorials First and foremost is the official “Start” page which links to several things, including the official tutorial. A warning: the tutorial is quite comprehensive, and is not really designed for zero-experience beginners. It also has some blind spots, for example it does not feature any advice on installing Python, or deploying your website to the actual internet. The Django Girls tutorial is a full guide to creating and deploying a blog for free. This organization uses it to teach weekend workshops to … -
Convert SVG Icons To CSS Webfonts and Deploy to CDN
If you're like me, you've undo... -
Create a Standalone React App
This post will answer the foll... -
10 Common Design Mistakes… and How to Avoid Them
Design work is complex business. It’s far too easy to mess up. To create high-quality products, all of the small details are crucially important. Each detail must be taken into account. It can be easy to get lost in the details and lose sight of the big picture. That’s why there are several incredibly common user interface (UI) design mistakes and weaknesses. The post 10 Common Design Mistakes… and How to Avoid Them appeared first on Distillery. -
Hello Linux: Celery & Supervisor
<div class='alert alert-succes... -
Hello Linux: Install Redis
<div class='alert alert-succes... -
Tips for Testing Django Views
Views are probably the most essential part of a Django application. They provide an interface to your application for users or other external applications. It only makes sense that these need to be well-tested. At first, it can seem difficult and/or tedious to write unit tests for them. However, by decoupling your business logic from … Continue reading Tips for Testing Django Views The post Tips for Testing Django Views appeared first on concise coder.