Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Fallback values in Django
It's not uncommon to have some type of cascading of values in a system. For instance, in our software, we allow a `Brand` to have some default settings, and then a `Location` may override some or all of these settings, or just fallback to the brand settings. I'm going to have a look at how this type of thing can be implemented using Django, and a way that this can be handled seamlessly. We'll start with our models: {% highlight python %} class Brand(models.Model): brand_id = models.AutoField(primary_key=True) name = models.TextField() class Location(models.Model): location_id = models.AutoField(primary_key=True) brand_id = models.ForeignKey(Brand, related_name='locations') name = models.TextField() WEEKDAYS = [ (1, _('Monday')), (2, _('Tuesday')), (3, _('Wednesday')), (4, _('Thursday')), (5, _('Friday')), (6, _('Saturday')), (7, _('Sunday')), ] class BrandSettings(models.Model): brand = models.OneToOneField(Brand, primary_key=True, related_name='settings') opening_time = models.TimeField() closing_time = models.TimeField() start_day = models.IntegerField(choices=WEEKDAYS) class LocationSettings(models.Model): location = models.OneToOneField(Location, primary_key=True, related_name='_raw_settings') opening_time = models.TimeField(null=True, blank=True) closing_time = models.TimeField(null=True, blank=True) start_day = models.IntegerField(choices=WEEKDAYS, null=True, blank=True) {% endhighlight %} We can't use an abstract base model here, because the `LocationSettings` values are _all_ optional, but the `BrandSettings` are not. We might have a look later at a way we can have a base model and inherit-and-change-null on the fields. In … -
Evennia 0.9 released
Last week we released Evennia 0.9, the next version of the open source Python MU* creation system.This release is the result of about 10 months of development, featuring 771 commits, 70 closed pull requests from the community and something like 80 issues and feature/requests closed. Thanks everyone!The main feature of Evennia 0.9 is that we have finally made the move to Python3. And we burn the bridges behind us; as announced in previous posts we completely drop Python2 support and move exclusively to only support the latest Python3.7.Overall the move to Python3 was not too bloody (and much work towards a never published py2+3 version was already done by Evennia contributors in a separate branch earlier). The main issues I ran into were mainly in the changes in how Python3 separates strings from bytes. This became crticial since Evennia implements several connection protocols; there were a lot of edge cases and weird errors appearing where data went to and from the wire.A regular user has it a lot easier though. So far people have not had too much trouble converting their games from 2.7 to 3.7. The biggest Linux distros don't all have Py3.7 out of the box though, so … -
What Is DevOps? Here Are the Core Concepts You Actually Need to Know
Over the past few years, DevOps has rapidly gained in popularity. We hear news near-constantly about how organizations worldwide are being transformed with the help of DevOps, and how engineers are mastering the new profession of DevOps. But what actually is the definition of DevOps? Is it a methodology, a profession, or both at once? What’s the difference between CI and CD, or between IaaS, PaaS, and SaaS? How do DevOps and SRE relate to each other? And what other terms and concepts do you need to know to understand the language and meaning of DevOps? DevOps Concepts You Need to Know — A DevOps Glossary To answer the question, “What is DevOps?”, Dmitry Stepanenko, Distillery’s Head of DevOps, has prepared a glossary of core concepts and definitions you need to know. Our DevOps glossary cuts through the clutter, defining and explaining only the terms you really need to know, including: A Definition of DevOps CI and CD: The Backbone of DevOps TDD and Microservices: The Development Side of DevOps Virtual Machines and Cloud Computing IaaS, PaaS, and SaaS Containers and Kubernetes Infrastructure as Code — the Confluence of “Dev” and “Ops” What Is the Definition of DevOps? DevOps — … -
Celery, Rabbits, and Warrens
Every time I pick up the Python job queue Celery after not using it for a while, I find I’ve forgotten exactly how RabbitMQ works. I find the Advanced Message Queuing Protocol (AMQP) concepts drop out of my head pretty quickly: Exchanges, Routing Keys, Bindings, Queues, Virtual Hosts… I’ve repeatedly returned to the blog post “Rabbits and Warrens” by Jason J. W. Williams to refresh my mind on the concepts. I saved it into my Evernote on December 2014, but unfortunately it has gone offline since. Luckily it’s saved in the Web Archive. If you use Celery with an AMQP backend, or RabbitMQ, it’s worth reading. My Favourite Bit Here’s the the extract that helps clarify things the most for me. First, the basic AMQP building blocks: There are four building blocks you really care about in AMQP: virtual hosts, exchanges, queues and bindings. A virtual host holds a bundle of exchanges, queues and bindings. Why would you want multiple virtual hosts? Easy. A username in RabbitMQ grants you access to a virtual host…in its entirety. So the only way to keep group A from accessing group B’s exchanges/queues/bindings/etc. is to create a virtual host for A and one for … -
Python 3 GUI: wxPython 4 Tutorial - Urllib & JSON Example
In this tutorial, we'll learn to build a Python 3 GUI app from scratch using wxPython and Urllib. We'll be consuming a third-party news REST API available from newsapi.org which provides breaking news headlines, and allows you to search for articles from over 30,000 news sources and blogs worldwide. We'll use Urllib for sending HTTP requests to the REST API and the json module to parse the response. Throughout you'll understand how to create desktop user interfaces in Python 3, including adding widgets, and managing data. In more details, you'll see: How to use Urllib to send HTTP requests to fetch JSON data from a third-party REST API. How to use the json module to parse JSON data into Python 3 dictionaries. How to use the webbrowser module to open URLs in your default web browser. First of all, head over to the registration page and create a new account then take note of the provided API key which will be using later to access the news data. What is wxPython wxPython is a Python wrapper around wxWidgets - the cross platform C++ library for building desktop apps for macOS, Linux and Windows. wxPython was created by Robin Dunn. Prerequisites … -
Simple bash deployment script for Django
#!/bin/bash remote=$1 cmd=$2 if [[ ! "${remote}" ]]; then echo No remote given, aborting, try username@host exit 1 fi if [[ ! "${cmd}" ]]; then echo No command given, aborting, try switch or nop exit 1 fi python=/usr/bin/python3.5 commit=$(git rev-parse HEAD) date=$(date +%Y%m%d_%H%M%S) name="${date}_${commit}" src="${name}/git" settings="${src}/src/conf/settings/" venv="${name}/virtualenv" archive="${name}.tar.gz" previous="previous" latest="latest" set -e echo "Transfer archive..." git archive --format tar.gz -o "${archive}" "${commit}" scp "${archive}" ${remote}: rm -f "${archive}" echo "Set up remote host..." ssh "${remote}" mkdir -p "${src}" ssh "${remote}" tar xzf "${archive}" -C "${src}" ssh "${remote}" virtualenv --quiet "${venv}" -p ${python} ssh "${remote}" "${venv}/bin/pip" install --quiet --upgrade pip setuptools ssh "${remote}" "${venv}/bin/pip" install --quiet -r "${src}/requirements.txt" echo "Set up django..." ssh "${remote}" "${venv}/bin/python ${src}/src/manage.py check" ssh "${remote}" "${venv}/bin/python ${src}/src/manage.py migrate --noinput" ssh "${remote}" "${venv}/bin/python ${src}/src/manage.py collectstatic --noinput" if [[ "$cmd" == "switch" ]]; then echo "Switching to new install..." ssh "${remote}" rm -f "${previous}" ssh "${remote}" mv "${latest}" "${previous}" ssh "${remote}" ln -s ${name} "${latest}" ssh "${remote}" 'kill -15 $(cat previous/git/src/gunicorn.pid)' echo "Deleting obsolete deploys" ssh "${remote}" /usr/bin/find . -maxdepth 1 -type d -name "2*" \ grep -v $(basename $(readlink latest)) | \ grep -v $(basename $(readlink previous )) \ | /usr/bin/xargs /bin/rm -rfv fi echo "Cleaning up..." ssh … -
Simple bash deployment script for Django
This is an update for the post https://kuttler.eu/en/post/django-deployments-without-downtime/ Raw #!/bin/bash # Fixed settings commit=$(git rev-parse HEAD) date=$(date +%Y%m%d_%H%M%S) name="${date}_${commit}" src="~/${name}/git" venv="~/${name}/virtualenv" manage="${venv}/bin/python ${src}/src/manage.py" manage_latest="~/latest/virtualenv/bin/python latest/git/src/manage.py" archive="${name}.tar.gz" previous="previous" latest="latest" # Dynamic settings python=/usr/bin/python3.5 pidfile="${previous}/git/src/project.pid" remote_suggestion="user@example.com" compilemessages=1 # Arg "parsing" cmd=$1 remote=${2:-${remote_suggestion}} if [[ ! "${remote}" ]]; then echo "No remote given, aborting, try ${remote_suggestion}" exit 1 fi if [[ ! "${cmd}" ]]; then echo No command given, aborting, try deploy remoteclean getdata exit 1 fi if [[ "${cmd}" == "deploy" ]]; then set -e echo "Transfer archive..." git archive --format tar.gz -o "${archive}" "${commit}" scp "${archive}" "${remote}:" rm -f "${archive}" echo "Set up remote host..." ssh "${remote}" mkdir -p "${src}" ssh "${remote}" tar xzf "${archive}" -C "${src}" ssh "${remote}" virtualenv --quiet "${venv}" -p ${python} ssh "${remote}" "${venv}/bin/pip" install --quiet --upgrade pip setuptools ssh "${remote}" "${venv}/bin/pip" install --quiet -r "${src}/requirements.txt" echo "Set up django..." ssh "${remote}" "${manage} check" ssh "${remote}" "${manage} migrate --noinput" if [[ ${compilemessages} -gt 0 ]]; then ssh "${remote}" "cd ${src} && ${manage} compilemessages" fi ssh "${remote}" "${manage} collectstatic --noinput" echo "Switching to new install..." ssh "${remote}" rm -fv "${previous}" ssh "${remote}" mv -v "${latest}" "${previous}" ssh "${remote}" ln -s "${name}" "${latest}" echo "Killing old worker, pidfile ${pidfile}" ssh … -
Simple bash deployment script for Django
This is an update for the post https://kuttler.eu/en/post/django-deployments-without-downtime/ Raw #!/bin/bash # Fixed settings commit=$(git rev-parse HEAD) date=$(date +%Y%m%d_%H%M%S) name="${date}_${commit}" src="~/${name}/git" venv="~/${name}/virtualenv" manage="${venv}/bin/python ${src}/src/manage.py" manage_latest="~/latest/virtualenv/bin/python latest/git/src/manage.py" archive="${name}.tar.gz" previous="previous" latest="latest" # Dynamic settings python=/usr/bin/python3.5 pidfile="${previous}/git/src/project.pid" remote_suggestion="user@example.com" compilemessages=1 # Arg "parsing" cmd=$1 remote=${2:-${remote_suggestion}} if [[ ! "${remote}" ]]; then echo "No remote given, aborting, try ${remote_suggestion}" exit 1 fi if [[ ! "${cmd}" ]]; then echo No command given, aborting, try deploy remoteclean getdata exit 1 fi if [[ "${cmd}" == "deploy" ]]; then set -e echo "Transfer archive..." git archive --format tar.gz -o "${archive}" "${commit}" scp "${archive}" "${remote}:" rm -f "${archive}" echo "Set up remote host..." ssh "${remote}" mkdir -p "${src}" ssh "${remote}" tar xzf "${archive}" -C "${src}" ssh "${remote}" virtualenv --quiet "${venv}" -p ${python} ssh "${remote}" "${venv}/bin/pip" install --quiet --upgrade pip setuptools ssh "${remote}" "${venv}/bin/pip" install --quiet -r "${src}/requirements.txt" echo "Set up django..." ssh "${remote}" "${manage} check --deploy" ssh "${remote}" "${manage} migrate --noinput" if [[ ${compilemessages} -gt 0 ]]; then ssh "${remote}" "cd ${src} && ${manage} compilemessages" fi ssh "${remote}" "${manage} collectstatic --noinput" echo "Switching to new install..." ssh "${remote}" rm -fv "${previous}" ssh "${remote}" mv -v "${latest}" "${previous}" ssh "${remote}" ln -s "${name}" "${latest}" echo "Killing old worker, pidfile ${pidfile}" … -
Testing email in Django
Sending email from a web app often seems like throwing stones into a black hole. You create a message, pass it to a mail send function and hope for the best. You don't control an inbox and mail server, so this whole process happens somewhere in between, and you ... Read now -
Series A Funding: Why Outsourcing Should Be Part of Your Startup Growth Strategy
You’ve raised your seed funding round and are on the path to Series A — Your startup shows promise! Investors have taken note. That’s fantastic, and we’re excited for you. But we also want to make it clear: Nowadays, to be a successful startup, you need to get right back to thinking about how you can spend that seed funding as wisely as possible. And you need to start thinking ASAP about how you’ll ensure your startup is deemed worthy of any additional funding. Why the super-practical downer advice? While more startups than ever are getting seed money, fewer than ever are getting follow-on funding. So that Series A funding you’re hoping for? It’s not a given. Also, as accelerator Y Combinator always advises its startups, it’s not your money. Getting more money is dependent on showing you can be a smart spender with good margins and a sustainable business model. Let me explain. What’s the “Series A Crunch”? Analyzing Seed vs. Series A Funding The venture capital community coined the term “Series A Crunch” to describe a trend they saw in Series A funding. Essentially, they noted that, while huge numbers of startups were easily raising large sums in … -
Form field and database feature
I know this post is way overdue. I haven’t been feeling well lately and there were some things in life I need to catch up with. Anyway, I still try to make progress in my project whenever I can. In these past two weeks, I’ve added a form field for my JSONField. I have also done some improvements to the tests and the field itself. I feel like there isn’t much to write about this time, since most of the work is documented on the GitHub PR. Compared to its model fields, Django’s form fields are easier to write. This time, the Django documentation isn’t very helpful. However, with the JSONField form field available in contrib.postgres, we can reuse most of its code for our cross-DB JSONField’s form field. I won’t go into details of each method in the form field, since the form field from contrib.postgres already works out of the box. However, I’ll try to add support for custom JSON encoder and decoder that will be used in the field’s validation. It’s very easy. I just needed to add the encoder and decoder to the field’s constructor like this: def __init__(self, encoder=None, decoder=None, **kwargs): self.encoder, self.decoder = encoder, … -
Responses versus Requests-Mock
Last October, I swapped out using Responses for Requests-Mock in my Python projects. Both are libraries for achieving the same goal of mocking out HTTP requests made with the popular Requests library. I swapped on my private and open source projects. For example of the transition, see my PR on ec2-metadata. Responses is still vastly more popular than Requests-Mock. At time of writing, Responses has 2,376 GitHub stars to Requests-Mock’s 257 (92 + 165 from its original repository). I’m writing this post as a bit of promotion for such a useful library, and also to give an example of my reasoning behind choosing one open source library over another. This is not to disparage Responses - it works really well, I’ve enjoyed using it, and have even contributed to it several times. Project Health The more people use a project, the more likely it solves the problem well, its “sharp corners” have been “sanded off”, and bugs have been fixed. We also want to see this continuing over time to know that we’re likely to be supported going forwards. Here are the statistics on each project: responses https://github.com/getsentry/responses/commits/master 2070 stars, 57 contributors. With this much support, unlikely to have many … -
How to use SCSS/SASS in your Django project (Python Way)
In this blog post, I will talk about how to use SCSS/SASS in your Django project with Python package. -
How to Set Up a Centralized Log Server with rsyslog
For many years, we've been running an ELK (Elasticsearch, Logstash, Kibana) stack for centralized logging. We have a specific project that requires on-premise infrastructure, so sending logs off-site to a hosted solution was not an option. Over time, however, the maintenance requirements of this self-maintained ELK stack were staggering. Filebeat, for example, filled up all the disks on all the servers in a matter of hours, not once, but twice (and for different reasons) when it could not reach its Logstash/Elasticsearch endpoint. Metricbeat suffered from a similar issue: It used far too much disk space relative to the value provided in its Elasticsearch indices. And while provisioning a self-hosted ELK stack has gotten easier over the years, it's still a lengthy process, which requires extra care anytime an upgrade is needed. Are these problems solvable? Yes. But for our needs, a simpler solution was needed. Enter rsyslog. rsyslog has been around since 2004. It's an alternative to syslog and syslog-ng. It's fast. And relative to an ELK stack, its RAM and CPU requirements are negligible. This idea started as a proof-of-concept, and quickly turned into a production-ready centralized logging service. Our goals are as follows: Set up a single VM … -
How to Set Up a Centralized Log Server with rsyslog
For many years, we've been running an ELK (Elasticsearch, Logstash, Kibana) stack for centralized logging. We have a specific project that requires on-premise infrastructure, so sending logs off-site to a hosted solution was not an option. Over time, however, the maintenance requirements of this self-maintained ELK stack were staggering. Filebeat, for example, filled up all the disks on all the servers in a matter of hours, not once, but twice (and for different reasons) when it could not reach its Logstash/Elasticsearch endpoint. Metricbeat suffered from a similar issue: It used far too much disk space relative to the value provided in its Elasticsearch indices. And while provisioning a self-hosted ELK stack has gotten easier over the years, it's still a lengthy process, which requires extra care anytime an upgrade is needed. Are these problems solvable? Yes. But for our needs, a simpler solution was needed. Enter rsyslog. rsyslog has been around since 2004. It's an alternative to syslog and syslog-ng. It's fast. And relative to an ELK stack, its RAM and CPU requirements are negligible. This idea started as a proof-of-concept, and quickly turned into a production-ready centralized logging service. Our goals are as follows: Set up a single VM … -
All Is Turned to Black
If the title worried you about my mental state, you can relax. It’s about the Python code formatter Black! Yesterday I finished converting the open source Python projects I maintain to use it. I’ve followed the project from a distance for a while, and figured now is a my time to try it out. It’s not out of beta yet, but it’s stable and gaining traction: My most recent client decided to use it on their codebase On Django we recently agreed on Django Enhancement Proposal (DEP) 8, which states Django will convert to Black when it leaves beta. It’s an unofficially official Python project, living on the Python GitHub Organization. The original author is Łukasz Langa, the Python 3.8 release manager, whom I saw speak last weekend at PyLondinium. Is the name some kind of “Black humo(u)r”? The name confuses some people. It’s a reference to Henry Ford, who quipped about the single colo(u)r option on his Model T: Any customer can have a car painted any color that he wants so long as it is black. Hence the project’s logo bears similarity to the Ford motors one: Black similarly tries to be “one style fits all” with the … -
5 Communication Mistakes That Are Hurting Your IT Outsourcing Relationship
When done right, IT outsourcing can provide businesses with a massive competitive advantage, powering innovation, sustainable scaling, cost savings, budget/staffing flexibility, and countless other benefits. It makes IT leaders’ lives easier, making them look good while driving value for the business. Again, however, that’s when it’s done right. So how can you avoid doing it wrong? Much of the success of any IT outsourcing relationship boils down to a single factor: effective communication. Communication mistakes are incredibly common in outsourcing. Below, we’ve broken down five of the most common mistakes, explaining the problems, their potential impact, and how you can avoid them. Communication Mistake #1: Micromanaging The Problem It’s your business and therefore your baby. It’s not surprising that it can be difficult to give up control over how things get done. So you become overly prescriptive in telling your IT outsourcing provider how they should do your work. After all, you don’t want to risk they’ll do things wrong. The Damage Reduced productivity, efficiency, and quality. Your IT outsourcing provider is increasingly hamstrung in how they can serve you. You’ve narrowed the definitions of what’s acceptable so much that it’s causing an entirely new set of problems. As they … -
Optimizing Postgres full text search in Django
Postgres provides great search capability out of the box. For the majority of Django apps there is no need to run and maintain an ElasticSearch cluster unless you need the advanced features ElasticSearch offers. Django integrates nicely with the Postgres search through the built in [Postgres module](https://docs.djangoproject.com/en/2.2/ref/contrib/postgres/). For small data sets the default configuration performs well, however when your data grows in size the default search configuration becomes painfully slow and we need to enable certain optimizations to keep our queries fast. This page will walk you through setting up Django and Postgres, indexing sample data and performing and optimizing full text search. The examples go through a Django + Postgres setup, however the advice is generally applicable to any programming language or framework as long as it uses Postgres. **If you're already a Django veteran you can skip the first steps and jump right into the optimization.** # Table of Contents * [Project setup](#project-setup) * [Creating models and indexing sample data](#creating-models) * [Optimizing search](#optimizing-search) * [Specialized search column and gin indexes](#specialized-column) * [Postgres triggers](postgres-triggers) * [Measuring the performance improvement](#measuring) * [Drawbacks](#drawbacks) * [Conclusion](#conclusion) ## Project setup Create the directories and setup the Django project. ```bash mkdir django_postgres cd django_postgres … -
Django Favicon Tutorial
How to add a favicon to any Django website. -
Types of Outsourcing: How to Choose the Best Solution for Your Business
To stay competitive, more businesses than ever are turning to outsourcing. These businesses know that leveraging one or more types of outsourcing helps them: Execute and innovate faster. From 2016 to 2018, Deloitte saw an increase from 20% to 49% in the number of organizations moving to outsourced providers as they innovate. Source top talent with the right expertise. Gartner’s 2017 and 2016 CIO Agenda Reports identified talent as the “single biggest issue standing in the way of CIOs achieving their objectives.” Make smarter use of their resources. As the Harvard Business Review states, “Full-time employees are the most expensive and least flexible source of labor.” That’s why smart businesses are making strategic use of outsourced, contract workers to fill gaps in expertise, meet fluctuating demands, and manage certain projects. Did you know that Microsoft and Google both have contract workforces that either equal or exceed their in-house headcounts? Done correctly, outsourcing can be your secret weapon to ongoing innovation, rapid releases, and sustainable business success. This guide will help you gain a stronger grasp on how different types of outsourcing models really work, so you can accurately assess which model is the right fit for your needs. We’ll start … -
How to maintain user session across sub domains in Django
Nowadays, people are using wildcard domains to provide same user experience across different domains. Using subdomains, we can be able to host multiple sites with the same domain name with the same code in a less time. To enable wildcard subdomains for your site, you should add CNAME record like. *.testsite.com CNAME YOUR_IP_ADDRESS With this, you can be able to access your site domain with abc.testsite.com, xyz.testsite.com, etc. After enabling wildcard domains, you should update your nginx file to accept wildcard domain requests. server { listen YOUR_IP_ADDRESS; server_name testsite.com, *.testsite.com; ... } With the above nginx settings, you're able to access requests from wildcard domains like normal domain. Now you've different wildcard domains for your site(testsite.com). When user login into testsite.com, redirects to the wildcard domain(abc.testsite.com) we should maintain same user session across subdomains. By default, django application isn't maintaining same user session across subdomains. To maintain this, we should add following details to the application settings file. SESSION_COOKIE_DOMAIN = ".testsite.com" DOMAIN_NAME = "testsite.com" Here SESSION_COOKIE_DOMAIN should start with '.' character followed by DOMAIN_NAME. This will handle and enable user session/cookies across wildcard domains(abc.testsite.com, xyz.testsite.com, testsite.com) Note: In local development, your … -
Caching tricks with Cloudflare workers
*tl;dr: Cloudflare allows you to vary their cache responses by arbitrary headers, such as Cookies or User-Agent. This requires you to have an enterprise account (~$5000). You could either pay $5000 or solve the problem with $5 and some Javascript code.* ## Intro Cloudflare offers caching on their global CDN. For sites that rarely update Cloudflare handles most of the traffic for you without ever reaching your origin server. Once a user visits a specific page, Cloudflare keeps the page response in the cache and serves it for the next visitor. This reduces the load on your servers while also improving the page performance since it's served closer to the user via one of [Cloudflare's POPs](https://www.cloudflare.com/en-au/network/). While this is great in theory, it's challenging to implement for any site that requires page customization per visitor (read: most sites). For example: we may want to serve different cache responses based on the cookie (unique caching per visitor) or on the User-Agent (unique caching per device type - mobile / tablet / desktop). Luckily, Cloudflare allows you to vary the cache by HTTP headers: - `Accept-Encoding` - caches each resource by the encoding of the payload. - `Cookie` - allows the cache … -
Writing JSONField from scratch
Last week, I improved an existing Django package and implemented some SQLite lookups for its JSONField to get some sense of how Django model fields work. This week, I tried to create a unified JSONField from scratch. It’s unified in the sense that it works on all database backends supported by Django. I also set up docker containers to run Django’s test suite with all database backends with the help of django-docker-box (though I ended up making my own for Oracle since it’s a bit more complex). However, I’m just going to talk about writing the field as that’s more interesting. As before, the docs on how to write custom model fields is very handy. I started building my own JSONField and got it working in a relatively short time. Not without bugs and quirks I had to deal with on each database backend, though. First, I wrote the code with SQLite as the top priority. I overrode the db_type method so it returns json. It’s also the name of the data type used in MySQL and MariaDB for JSON values, so I guess it’s a good start. def db_type(self, connection): return 'json' This means that the SQL query for … -
Drafting a POC JSONField for SQLite
There’s this neat little python package called django-jsonfallback. It’s made by one of my mentors. To quote the description, this package allows you to Use PostgreSQL’s and MySQL’s JSONField, but fall back to a TextField implementation on other databases. Since my project is to bring a cross-DB JSONField, this project is very useful for me as a starting point. To get a better understanding of how that package works (and how Django model fields work in general), I did a good read on these wonderful Django docs about custom model fields and custom lookups. I also found this interesting Custom Database Backends presentation from Django Under the Hood 2016 event. As explained in the docs and presentation, you can create as_vendor methods such as as_mysql, as_sqlite, etc. to create different implementations of lookups and transforms (it also applies for any class that extends BaseExpression, if I’m not mistaken). I began looking at the code in django-jsonfallback, and I found that it was made with some if conditionals to check for the database backend. I tried replacing the as_sql methods with as_mysql as you can see in this pull request, and it worked pretty well. I also tried to replace the … -
Community Bonding and getting started
In the official GSoC timeline, there’s a Community Bonding period on May 7 - 27. To quote the glossary, it’s The period of time between when accepted students are announced and the time these students are expected to start coding. This time is an excellent one to introduce students to the community, get them on the right mailing lists, working with their mentors on their timeline for the summer, etc. At the start this period, we’re also given emails from Google about what we need to do. We are tasked to set up a Payoneer account to receive our stipend later. We were also invited to a mailing list for current (and past) students. Some students decided to create a Telegram group for discussions with other students all over the world. I posted on the django-developers mailing list to ask about communication channels we’ll use during the program, and one of my mentors said that he will send an email to get me (and another student) started. On May 13, my mentors (there are four) sent introductory emails on how to get started. The plans are quite similar to what I put in my proposal, so I guess I’m on …