Building a Django Continuous Integration and Delivery Pipeline to AWS
Tuesday January 30 2018

Building a CI/CD (Continuous Integration / Continuous Delivery) flow for your web application is a must nowadays. With so many things that can go wrong, and the amount of time and effort the deployment process of an application takes, a flow like this will give you peace of mind that your application is running without (or with less) errors and that your application will be production ready on every new commit to its source code.

In this post I want to talk about building such a pipeline, with emphasis on deploying a Django 1.11 application to AWS ElasticBeanstalk, which is an Amazon service very similar to Heroku. Additionally I will talk about how to include other services to the delivery flow, such as Amazon S3 for storage of static files and Amazon RDS (Relational Database Service) for a relational database that will be connected to our application.

The pipeline will work as follows:

  1. Code will be pushed to source control repository. For this article, I will use Github.
  2. Project will be built and tested in a CI job at TravisCI.
  3. TravisCI will perform a deployment to ElasticBeanstalk once the build passes successfully.

We will be using both the ElasticBeanstalk CLI (ebcli) and the AWS ElasticBeanstalk Console to achieve this.


Read more...


Django Dynamic Queryset Filtering With Pagination
Wednesday January 17 2018

This blog article does a very good job at explaining how to setup dynamic queryset filtering in Django. However, it doesn't go into paginating the filtered queryset results.

I had a very hard time trying to implement this pagination feature using class based views. More specifically, using the FilterView that comes with the django-filter package.

In the end it turned out to be very simple. The documentation was a bit misleading on this so it took a while to understand and find the solution.


Read more...


Django AJAX Search With Elasticsearch
Wednesday January 10 2018

In this post I want to go over how I implemented a very neat AJAX search using Elasticsearch in Django. Let's get started!

The Search Template

The starting point of our search feature will be the search template. That is, the template that contains the input field where the user will type in the search keywords.

This template is extremely simple and does not need a <form> tag. I will create it as a partial under templates/search.html:

{% csrf_token %}
<input id="search" name="q" placeholder="Search...">

Notice how we have given the input a name with the value of q. This will be important when our view receives the query from this input field.

I can then render this partial in the main template like this:

{% include 'search.html' %}

Read more...


Java JTable Tricks
Wednesday December 20 2017

Java's JTable is a GUI component that has been around for many many years. While a bit difficult to work with, it's almost a mandatory component in an application that displays a lot of data.

In this post I share some nice tricks for working with JTables in Java applications.

Scrolling

A JTable by itself does not provide any scrolling when handling a lot of data. To fix this, we need to place the table inside a JScrollPane component. Additionally, we can place this JScrollPane into a JPanel in our window:

myPanel.add(new JScrollPane(myTable,
    JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)
    );

Read more...


Bulk Create With Django REST Framework
Monday November 27 2017

In this quick post I will go over how to create an endpoint that allows bulk creation of a resource using Django REST Framework.

The Serializer

Let's assume that we will be working with an existing Book model in our Django application. We will create a serializer for this model using Django REST's ModelSerializer helper class:

# serializers.py
from myapp.models import Book
from rest_framework import serializers


class BookSerializer(serializers.ModelSerializer):
    class Meta:
        model = Book
        fields = '__all__'

The "__all__" string indicates that we want to serialize all of the model's fields.


Read more...