-
ValueError: invalid literal for int() with base 10 when do Django Filter()
Do you got this error while doing filter QuerySet in Django: 1ValueError: invalid literal for int() with base 10: It just simply mistake that may you usually do by filter() with args or kwargs. This is some bad code :
-
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 […]
-
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 | … […]
-
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’ […]
-
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
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 […]
-
coercing to Unicode: need string or buffer, FieldFile found Django
When I try to send Content File in Django, I got this error : 12xmlrpclib.Fault: <fault 1: "<type ‘exceptions.TypeError’>:coercing to Unicode: need string or buffer, FieldFile found"> </fault> Then i suddenly that making a dumb mistake. Watch this codes :
-
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
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 | |__ […]
-
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 […]
-
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 […]
-
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 […]
-
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", […]
-
How to add / import / load JAR into Java project in Eclipse using Build Path
Importing JAR / Modules in Java is a little bit different with Python / PHP / Ruby or another programming. In Java, IDE will handle all we need, for instance Eclipse. When we have custom modules like Json Simple Parser and need to add into our Java Project, then we should follow the right path […]
-
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", […]
-
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
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 […]
-
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 […]
-
Regex match / search list of word by separate spaces, number, words with spaces using Python
This is example of using re module for building regex. Searching match words that contains spaces or separate with spaces or more than one spaces and number. This is most basic things that may faced in daily development. First, let’s create sample text, eg :
-
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 […]
-
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 […]
-
How to configure and enable Logging / logger in Django for MySQL Database Query
We can see what query made by Django by configure and enable logger. Logger in Django is using python logging, so it will have same rule level. We should use “Debug” mode to log and watch query database into our django server development. Then we can start by editing settings.py :
-
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 […]
-
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 […]
-
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
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 […]
-
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 reset postgres password in PostgreSQL Ubuntu 11.10 Oneiric
Reset postgres user password in PostgreSQL Ubuntu 11.10 Oneiric is very simple. First, make sure you have set trust mode in pg_hba.conf ( /etc/postgresql/9.1/main/pg_hba.conf ), for instance : 123456local all postgres trust # […]
-
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 […]