Hacks by Ruddra

Use VS Code Inside Docker Container for Development

VS Code is the popular IDE at the moment. You can use it for developing applications in almost any programming language. In addition to that, you can do remote development in Docker,VM etc. In this post, we are going to discuss about how to use Docker Environment in VS Code.

Django Serialize ForeignKeyField, ManyToManyField, Instance and Property Method

Django’s serialization framework provides a mechanism for “translating” Django models into other formats. Usually they are in json, yaml, XML, GeoJSON etc text based formats. Here, we are going to supercharge these serializers to do more things, even try to render properties and instance methods. This article will be useful to you if you are:

Deploy Django App in Sub Directory Using Openshift

The Problem When you are using Openshift, you will be using routes to expose a route from a service. Let’s say you want to expose a path in example.com/dummy. When you do that for a django application(without any reverse proxy server), it usually becomes a problem, because the sub directory does not work well with Django’s urls.

Install MySQL and MySQLClient(Python) in MacOS

Connecting to MySQL from Python in MacOS is a very problemtic and painful process. In this post, we are going to see how to install MySQL and connect it from a Python Application using mysqlclient: Step One: Install Brew You need to install Homebrew in you local machine. You can do it by:

Create Proxy Object in Python

Lets say you have been using a class named ClassA, objects created from that class has been used in many places. Now you have a requirement that you need to make a simillar class ClassB, which has almost simillar functionality. Objects of ClassA and ClassB will have simillar method signatures, and could be swapable.

Do Extra in S3 Using Django Storage and Boto3

Today, I am going to write about few useful snippets/functionalities which I have used for Amazon S3 or any S3 compitable storage using Boto3 and Django Storage. FYI, this post focuses on using S3 with Django. So without further ado, lets begin: Configuring S3 When using django storage, you don’t need to put configurations like ~/.

Django: Save Unknown Object in Database

Suppose you are dealing with a poorly written API, which returns different type of objects at different scenarios. For example, sometimes it returns a string(ie. abcd), sometimes it returns a list(ie. [1,2,3,4]), or maybe None. Now, you are suppose to save that data, which you can’t predict. As you can’t predict the data type of object, you can’t design your Django Model accordingly.

Django: Ordering by Linked List for Model Objects

Linked list is a data structure where each object has points to next. In django, linked list can provide an interesting solution when it comes to custom ordering/grouping issues. Lets think of an example like this: you are making a blog site, and you have made a Post Model like this:

Django: Changing User Model in Mid-Project

Every now and then I see some questions pop up in stackoverflow with title: ValueError: Related model ‘app.User’ cannot be resolved This is a very common issue and pops up when the user tries to run the migration. So, lets talk more about what is this problem and how can we solve it.

Testing for Django Rest Framework with Factory Boy and Faker

“I’m not a great programmer; I’m just a good programmer with great habits.” ― Kent Beck Test Driven Development - in short TDD is a practice where you write the tests first then the actual code. It makes the code less vulnerable and it makes a testable software rather than writing the software, then test it.