Pytest has become my favorite Python testing framework. And in this article I want to go over on how I learned to write nice tests for Django and Django REST Framework.
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:
Code will be pushed to source control repository. For this article, I will use Github.
Project will be built and tested in a CI job at TravisCI.
TravisCI will perform a deployment to ElasticBeanstalk once the build passes successfully.
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.
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:
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: