Month: March 2013

Change / modify app labels urls in Django Admin

Change / modify app labels urls in Django Admin

We can update app labels / application name and urls in Django Admin without change the application name folder. For instance: 12App name : student_insurance Admin : /student_insurance What we want: 12App name : student_insurance Admin : /student-insurance By: 123456class YourModel(models.Model):     ….     class Meta:         app_label = string_with_title("student-insurance", …

+ Read More

Solve php-fpm consume high CPU usage 100% 200%

Solve php-fpm consume high CPU usage 100% 200%

Suddenly my server crashed and I see that php5-fpm usage was the culprit and it’s consume 100% of CPU usage. Fyi, I use NGINX and WordPress on this case. I tried several thing to solve php-fpm issue like change listener into socket instead of ports. Also, I use APC as well, but it’s doesn’t works. …

+ Read More

Django set urls conf on parents of apps with include and slug

Django set urls conf on parents of apps with include and slug

For instance, we have urls.py like this: 1(r’^insurances/’, include(‘insurances.urls’, namespace="insurances")), Then we want to have slug on parent of apps by : 1/insurances/slug Then in our urls.py in apps: 1url(r’^(?P<slug>[-w]+)/$’, ‘details’, name="details"), Done! 😀

Scroll down pages into bottom in Django Lettuce Selenium

Scroll down pages into bottom in Django Lettuce Selenium

The most common things happen when we have long pages is the element’s is not found or not clickable. 12345678Traceback (most recent call last):       File "/home/yodi/.virtualenvs/insurance/lib/python2.7/site-packages/lettuce/core.py", line 143, in __call__         ret = self.function(self.step, *args, **kw)       File "/home/yodi/web/insurance/../insurance/tests/step_definitions/web_steps.py", line 63, in i_press         …

+ Read More

Set readonly fields only for view details on Django Admin

Set readonly fields only for view details on Django Admin

In some condition we want to make fields became read-only on “view details” in Django Admin. That’s mean, for adding new records, this fields must be not in read-only mode. To solve this problems, we can use get_readonly_fields(). Here is an example: 1234567class InsuranceAdmin(admin.ModelAdmin):     list_display = (‘id’, ’email’, ‘brand’, ‘website’)     def …

+ Read More

Django south access orm another app

Django south access orm another app

To access another application in django south data migration fowards() or backwards(), we just use : 1orm["app_name.Model_name"] For instance, my app name is “insurance” and my model name is “Records”: 1orm[‘insurance.Records’].objects.all()

Django Mod WSGI Apache and Virtualhost on Fedora 17

Django Mod WSGI Apache and Virtualhost on Fedora 17

Here is a steps for setup Django with modwsgi + httpd + Virtualhost in Fedora 17. 1. Install Apache and Mod WSGI 1sudo yum install -u httpd* mod_wsgi 2. Load modwsgi To avoid error : 1invalid command ‘WSGIScriptAlias’, perhaps misspelled We need to check whether this line exists in “/etc/httpd/conf/httpd.conf”: 1LoadModule wsgi_module modules/mod_wsgi.so 3. Create …

+ Read More

Fix slow update query MySQL in Django Session table

Fix slow update query MySQL in Django Session table

After using new relic, i found there is query that took more than long time to finihed. After investigate, I found that “update query” on django session is the most expensive and slowest query. Here is the query: 1UPDATE `django_session` SET `session_data` = %s, `expire_date` = %s WHERE `django_session`.`session_key` = %s I’m wondering what the …

+ Read More

Solve Django OperationalError: (2013, ‘Lost connection to MySQL server during query’)

Solve Django OperationalError: (2013, ‘Lost connection to MySQL server during query’)

I got this errors when running my scripts that using multiprocessing to speed-up the task. 1OperationalError: (2013, ‘Lost connection to MySQL server during query’) Apparently, this problems occurs because another process try to open database connection that already opened by Django. To solve this problem, just close django database connection in your target worker function …

+ Read More

Setup Debian Server on HPCloud for production

Setup Debian Server on HPCloud for production

Here are quick steps to setup Debian server for production in HPCloud. I use Debian 6 on this example. 1. Install basic software 123apt-get update && apt-get upgrade apt-get install nmap vim bind9 mysql-server mysql-client apache2  php5 php-pear php5-suhosin php5-mysql python-dev nginx php5-common phpmyadmin apache2 zip unzip unrar-free imagemagick rsync python-pip dnsutils libxml2 libxml2-dev libxslt1-dev …

+ Read More

Solve Permission denied (publickey) EC2 to New Server

Solve Permission denied (publickey) EC2 to New Server

I use Debian AMI for this example. Suddenly, I can’t SSH into new server that created. Even worse, i can’t made SSH connection from one server to another server in Amazon EC2. Apparently, the problem is the way of make SSH connection. This is what Amazon EC2 suggestion: 1ssh -i my.pem root@<my-ip-address> And it give …

+ Read More

Solve MySQL Incorrect key file for table /tmp repair it in EC2

Solve MySQL Incorrect key file for table /tmp repair it in EC2

Today i got this errors while installing MySQL in my Debian : 1ERROR 126 (HY000) at line 1: Incorrect key file for table ‘/tmp/#sql_45cf_0.MYI’; try to repair it This errors usually refering for out of space in our server. I just replace server with new EBS which have more space. Then after doing “df -hT”, …

+ Read More

Ec2 fix ebs volume space

Ec2 fix ebs volume space

When creating new EBS from Snapshot in EC2, this EBS will using the old space. For instance, snapshot was 1GB and we launch new EBS with 5GB capacity. After attaching into EC2 server, we’ll find out that the space still the old one (1GB). To fix this EBS volume space, just use “resize2fs”: 1resize2fs /dev/xvda1