Month: February 2012

  • Understanding what is public static void main in Java class

    When looking class in Java, sometimes you see “public static void main” of some class name. So, let we learn about what it means in Java. First, we create a new Class in Java on files called “car.java” : 123456789101112class Car {     /** Default gear */     int gear = 1;   […]

  • How to called Class instance from given string variable in Python

    This is pretty interesting. You have give string list like “InsuranceUser”, “InsuranceUserProfile”, etc. That are string. Now, you should called class that have name same with the given string. I will show in Django models as more real explanation. To fetch InsuranceUser models, usually we do : 123from insurance.models import InsuranceUser user_list = InsuranceUser.objects.all()

  • How to make pep8 for long attribute / method chain in Python

    When we use 80 lines rules, sometimes we facing some difficult cases like long attributes. Usually this also happen in Django which need nested method chain for calling models. For instance : 1user_list = User.objects.filter(created__year=2012).order_by(‘user’).values(‘user’).distinct() We should shorten this long attributes. We should know that blackslash is “evil” in python. But, at this cases we […]

  • Example how to git submodule, add, delete submodule and use existed git repository

    Git submodule is great feature on Git which it will needed much on large projects than build by small parts. For example, I have single project called “Insurance”. This project contains several apps like “billing”, “user”, “backend” and several apps. We want to create single repository that contain several small repositories. Using git submodule will […]

  • Get list of unique month in each year and unique year in database Django

    This is common need where we need to list unique all year in database. Then we want each year contain list of unique month. I assume we have field called “created” and it have “datetime” fieldtype. So, basicaly it easy. First things, we need to list unique Year in database on Django using dates QuerySet. […]

  • Aggregate count all number on sliced Queryset (limit query) Django solved

    Django 1.3.1, Limiting Queryset with slice and count using Aggregate() will calculate all of rows. I don’t know why this happen, so I update this exists problem in django tickets. More detail explanation, I have Books models and want to calculate filtered books by Year: 123456books = Books.objects.filter(created__year=2012) # Will calculate all books total_books = […]

  • Setup Aptana For Python and Django Development with Checker, Tag, Linter

    Aptana Studio 3 provides several feature that ease our Python and Django development. Actually, to boost Aptana for our development, we should make customization in several preferences. I will explain into several steps about configure Aptana for Python and Django development. Anyway, I use Aptana Studio 3 and Ubuntu 11.10 (Oneiric) using Java 6 at […]