Month: February 2012

Filter DateTimeField Models with Date format in Django

Filter DateTimeField Models with Date format in Django

When we have DateTimeField, sometimes we have a need to filter it by Date. For example, given a models called “Insurance” : 123class Insurance(models.Model):     name = models.CharField(max_length=255)     created = models.DateTimeField() Given data : 12345678=================================== | Name     |  Created             | =================================== | Yodi   …

+ Read More

How to convert queryset models into list in Django

How to convert queryset models into list in Django

This is common question that we need to return Queryset in Django just to be a list. When I try ask to several friends, most of them show me bunch of iterating codes. For example : 1234567Insurance ============================ | ID   |  Client    | …  | ============================ | 1    | Yodiaditya |  … …

+ Read More

Learning property getter setter in Python

Learning property getter setter in Python

Property is new feature started in Python 2.2. It have great function to return attribute property when class derived from object. For example : 1234567891011class Insurance(object):     def __init__(self):         self.name = None         print(self.name)     def set_name(self):         self.name = ‘Popel’     …

+ Read More

Send content file from FileField Django models via XMLRPC

Send content file from FileField Django models via XMLRPC

Common cases, we need to send content file from FileField from django models via XML-RPC. In this example, I use django-xmlrpc to handle XMLRPC server. First, we have models : 1234from django.db import models class Insurance(models.Model):     file = models.FileField()

Marshal Django Models or QuerySet into dictionary and send via Django-XMLRPC

Marshal Django Models or QuerySet into dictionary and send via Django-XMLRPC

Django-XMLRPC provides quick way for build communication between django as server and client via XMLRPC. Some usual cases in using Django-XMLRPC is send dictionaries data into client. We need to convert Models / QuerySet in Django into dict or list. Luckly, Django have built-in function to convert models into dictionaries (recursive) called “model_to_dict”. Example usage …

+ Read More

Filter queryset child models related by parent models in Django

Filter queryset child models related by parent models in Django

As I explained in “Django query get parent related models from the child models“, we can made query parent models from child models relationship. Now, we will doing filter queryset of child models by parent models value. Given models example : 12345678910111213from django.db import models class Company(models.Model):     name = models.CharField(max_length=255) class Insurance(models.Model):   …

+ Read More

Django query get parent related models from the child models

Django query get parent related models from the child models

Get parent models queried from child models in Django is possible and easy. For example, we have this parent – child models relation : 12345678910111213from django.db import models class Company(models.Model):     name = models.CharField(max_length=255) class Insurance(models.Model):     company = models.ForeignKey(Company)     package = models.IntegerField(max_length=255) class Client(models.Model):     insurance = models.ForeignKey(Insurance)

Solve retrieve file name Django fileField with file.name that show full path

Solve retrieve file name Django fileField with file.name that show full path

When working with Django FileField, you usually need to retrieve filename with file.name. But, when you make query file.name, instead you got full path of filename. This is annoying, right? We can use templatetags to get basename of file.name by : 1. Create folder templatetags that contains __init__.py and filename.py 12345APPS   |   |__ …

+ Read More

Convert received datetime instance from XMLRPC server with datetime format in Python

Convert received datetime instance from XMLRPC server with datetime format in Python

This is commonly happen when you have Client or Server send datetime format through XML-RPC. Basically, you can’t use datetime format from received XML-RPC directly, because it have instance type, not datetime format. Also, this is why you can’t save datetime value from XML-RPC directly into Django Models because it need datetime format. Basically, datetime …

+ Read More

Example Create Simple List View / ListView in Android

Example Create Simple List View / ListView in Android

You better know about ListView while start learning Android. ListView will widely use in Android Development because scrollable of data is commonly used in creating applications. To use ListView, we should extends “ListActivity” rather than “Activity”. Basically, ListActivity is extending “Activity” to handle List of View. Another keyword while using ListView is called “Adapter”. ListAdapter …

+ Read More

Solve Uncaught exception ‘Zend_Json_Exception’ with message ‘Decoding failed: Syntax error

Solve Uncaught exception ‘Zend_Json_Exception’ with message ‘Decoding failed: Syntax error

Using Zend_JSON for parse invalid JSON format like “pain in the neck”. If you got this kind of error while parse JSON : 1Uncaught exception ‘Zend_Json_Exception’ with message ‘Decoding failed: Syntax error Or maybe : 1Uncaught exception ‘Zend_Json_Exception’ with message ‘Decoding failed: Unexpected control character found I suggest to you, move into json_decode() from native …

+ Read More

Example parse nested JSON array and Object Java

Example parse nested JSON array and Object Java

Parsing JSON in Java is same as with another language, but a little bit complex. I use JSON-Simple for parsing JSON and accessing nested JSON array and Object. For example, I have JSON nested structure like : 12345678{   "items": [     {       "kind": "shopping#product",       "id": "tag:google.com,2010:shopping/products/10048/187970250782485989",   …

+ Read More

How to open PostgreSQL remote access with IP address limitation on Ubuntu

How to open PostgreSQL remote access with IP address limitation on Ubuntu

When trying to configure postgresql to be able accessed remotely from another IP address, we usually got several errors like this : 1234postgresql remote access no pg_hba.conf entry for host psql: FATAL:  no pg_hba.conf entry for host "xxxxx", user "xx", database "xxxx", SSL on FATAL:  no pg_hba.conf entry for host "xxxx", user "xx", database "xxx", …

+ Read More

Generate PDF with XHTML2PDF Pisa in Django Examples

Generate PDF with XHTML2PDF Pisa in Django Examples

Generating PDF using XHTML2PDF pisa in Django is pretty easy. Here are example / cases how to generate PDF in Django. First things to do is installing XHTML2PDF and PIL with Zlib support. In this example, we will generate templates/app/test.html.

How to change font bold style of php HTML in Aptana Studio

How to change font bold style of php HTML in Aptana Studio

When opening HTML, CTP or another PHP-HTML files in Aptana Studio 3, i found that all using bold which is annoying for me. So, to make it to be normal fonts : 1. Go to Aptana Studio menu -> “Window Menu” 2. Type “Themes” on left search box. 3. Find element “text.html.basic” and change it …

+ Read More

How to load images files style css in pdf using pisa xhtml2pdf on Django

How to load images files style css in pdf using pisa xhtml2pdf on Django

This problem is widely affected by many developer that use pisa xhtml2pdf with Django. Usually, they failed to load images and styles into pdf using Django templates. There are two posibilites here why this is happen. 1. Incorrect of generate PDF without include resources We should pointing our resource (STATIC and MEDIA) path into link_resource …

+ Read More

Solve media directory and URL not found in Django

Solve media directory and URL not found in Django

Un-detected / not found media files folder in Django using development webserver is commonly happen in Django pitfalls. When configure media directory / folder in Django, you should watch several things to make it loaded properly. Miss-configure of media in Django will lead you into Error media files or not found. So, basically, media folder …

+ Read More

How to enable TOR open for remote access with Polipo on Ubuntu

How to enable TOR open for remote access with Polipo on Ubuntu

Tor usually installed and running on 127.0.0.1 port 9050 which it’s can’t be accessed from outside. We can open this local listen address TOR signed into IP network and run as HTTP Proxy with Polipo. FYI, I use Vagrant and running Ubuntu Oneiric on Guest. I install TOR in Vagrant guest and accessed it remote …

+ Read More

How to login into HPCloud Instance and edit Security Group using Hybridfox

How to login into HPCloud Instance and edit Security Group using Hybridfox

Hybridfox is great tools for connecting with our cloud server. When you configure HPCloud server, then you should have this for manage your security groups and allowing several ports to be open. Because default group in HPCloud only allowing SSH port only. I use the latest Firefox (10 and always updated through update-manager). Then you …

+ Read More

Relation between activity, xml, views, intent and layout in Android

Relation between activity, xml, views, intent and layout in Android

As a new guy, Android looks like simple if we already have know how the relation between components. From my friends who Android Developer, he said there are 3 important components in building Android applications : 1. Activity 2. Services 3. Intent 4. View But for now, we will learn about corelation between activity, xml …

+ Read More

Awk sed total bot access.log Apache Ubuntu

Awk sed total bot access.log Apache Ubuntu

We can mining and calculate Bot from access.log Apache2 using awk and sed. To get rank and total list of Bot that visit our webpages, then go to “/var/log/apache2” and this scripts : 1awk ‘{print $12}’ access.log.1 | sort | uniq -c | sort -nr

Alternate or Shortcut way for get object DoesnotExist in Django

Alternate or Shortcut way for get object DoesnotExist in Django

Although this pretty documented in Django, but most of people still searching a way to make get() more short. So, usually people use get() and DoesNotExist() for searching models. Eg: 1234567from django.http import Http404 def my_view(request):     try:         my_object = MyModel.objects.get(pk=1)     except MyModel.DoesNotExist:         raise …

+ Read More

How to create user postgresql using Pgadmin Ubuntu

How to create user postgresql using Pgadmin Ubuntu

Create postgresql new user using Pgadmin in Ubuntu is very easy. First, launch your Pgadmin that used “postgres” account and connect into localhost. Then, after login, expand your “localhost” item and find “Login Roles“. Right click on “Login Roles”. Then create your users and setup the permission.

How to example create list view layout in Android

How to example create list view layout in Android

Today I will show you how to create simple list view in Android. I assume you already have “Hello World” projects. FYI, there are several Layout Views type in Android like : 1. Linear Layout 2. Relative Layout 3. Table Layout 4. Grid View 5. Tab Layout 6. List View For futhermore explanation of this …

+ Read More