Django

Showing choicefield in template Django

30 Sep , 2014  

For example, we have choicefield in models :

1
2
3
4
5
6
7
8
class Employee(CommonInfo):
    PROFILE_CHOICES = (
       (1, _("Hello")),
       (2, _("World")),
    )

    name = models.CharField(max_length=255, unique=True)
    profile = models.IntegerField(choices=PROFILE_CHOICES , default=1)

To showed value of profile in template, we can use

1
object.get_{name-of-choicefield}_display

So, example for this case will be object.get_profile_display

Django

Always clear *.pyc in your Django system in Server

29 Sep , 2014  

Make sure to remove pyc before deployment in Django by :

1
find . -name "*.pyc" -exec rm -rf {} \;

Mac OS X

Install Maverick ISO OS X with USB Bootable

27 Sep , 2014  

Screen Shot 2014-09-27 at 7.53.17 PM

1
diskutil list
1
sudo hdiutil convert -format UDRW -o ~/Desktop/Maverick.dmg ~/Desktop/Mavericks.iso
1
2
3
4
hdiutil convert -format UDRW -o ~/[path]/destinationISO.img ~/[path]/sourceISO.iso
sudo diskutil umount /dev/disk3s2
sudo dd if=/[path]/destinationISO.img.dmg of=/dev/disk3 bs=1m
sudo diskutil eject /dev/disk3

Django

Django reset migration and avoid default value in makemigration

26 Sep , 2014  

It’s common when we need to add new key and migration said we need to defined default values for the field (eg: using datetime). Well, there another trick we can use.

1. Remove all tables in apps
Yes, we create migration to remove all tables in apps. To do this, first go to APPS in settings.py. Put comments on all apps below your app which you want to reset. Let’s say, we have app “credit”. We need to modify models and assign into some foreignkey (null not allowed here).

Comment another app below credits.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
INSTALLED_APPS = (
    'grappelli',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts',
    'friends',
    'credits',
    #'memberships',
    #'rewards',
)

Then, make sure to comment admins.py under “credits”.

2. Generate migration to delete model credits.
Go to credits apps and edit models.py. We just comment all line inside models.py then do makemigration after.

1
2
3
4
5
Migrations for 'credits':
  0003_auto_20140926_1454.py:
    - Remove field a from credit
    - Remove field b from credit
    - Delete model Credit

When we run this migration, our tables will deleted.

3. Add your foreginkey or whatever things you need and makemigrations.

4. Done 🙂

Django

Solve Django makemigrations existing from initial

16 Sep , 2014  

When we already have migrations for our models and want to reset it in Django 1.7, it might be a bit tricky. All you need is to disable all apps in INSTALLED_APPS except your app which want to be reseted

Example, app which will reseted call “credits”. In INSTALLED_APPS :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Application definition
INSTALLED_APPS = (
    'grappelli',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts',
    'friends',
    'credits',
    'memberships',
    'rewards',
)

Then commented them into :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Application definition
INSTALLED_APPS = (
    'grappelli',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts',
    'friends',
    'credits',
    #'memberships',
    #'rewards',
)

Django

Django no module name

15 Sep , 2014  

When we got this errors :

1
2
3
ImportError at /accounttraders
No module named accounttrader
Request Method: GET

Just check urls.py and make sure to have correct apps name there.
For intance, my app name is “accounttraders” but i wrote “accounttrader” in urls :

1
2
3
4
from django.conf.urls import patterns, url

urlpatterns = patterns('',
    url(r'^$', 'accounttrader.views.index', name="account"),

Solved by

1
2
3
4
from django.conf.urls import patterns, url

urlpatterns = patterns('',
    url(r'^$', 'accounttraders.views.index', name="account"),

Android

Install Recovery Heimdall clockwok into Samsung S3 G9300 in Ubuntu

10 Sep , 2014  

1. Download and install heimdall
https://github.com/Benjamin-Dobell/Heimdall/downloads (Heimdall and Suite)

2. Install android adb

1
2
3
sudo add-apt-repository ppa:phablet-team/tools && sudo apt-get update
sudo apt-get install android-tools-adb android-tools-fastboot
sudo dpkg --add-architecture i386

3. Download recovery

1
wget -c http://download2.clockworkmod.com/recoveries/recovery-clockwork-6.0.4.6-i9300.img

4. Start Download Mode
Plug Samsung S3 into your laptop and execute console

1
2
adb reboot download
sudo heimdall flash --recovery recovery-clockwork-6.0.4.6-i9300.img --no-reboot

And you should see :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
This software is provided free of charge. Copying and redistribution is
encouraged.

If you appreciate this software and you would like to support future
development please consider donating:
http://www.glassechidna.com.au/donate/

Initialising connection...
Detecting device...
Claiming interface...
Attempt failed. Detaching driver...
Claiming interface again...
Setting up interface...

Checking if protocol is initialised...
Protocol is not initialised.
Initialising protocol...
Handshaking with Loke...

Beginning session...
Session begun with device of type: 131072

Downloading device's PIT file...
PIT file download sucessful

Uploading RECOVERY
100%
RECOVERY upload successful
Ending session...
Re-attaching kernel driver...

5. Reboot
Unplug the USB cable from your device Then Pull out your battery. Yes! we need to shutdown the devices and wait for 10 seconds before switch on.

You can boot the phone into recovery mode. Hold Home, Volume Up & Power. Be sure to reboot into recovery immediately after having installed the custom recovery

6. SD Card
Install from zip files

Reference :
http://wiki.cyanogenmod.org/w/Install_CM_for_i9300

Django

Django Realtime with Redis and NodeJS

10 Sep , 2014  

I’ve found good articles for this :
http://ipasic.com/article/django-redis-nodejs-real-time-applications/

OS

Solve Windows 8 Disk 100%

7 Sep , 2014  

After using Windows 8 for nearly 9 months, i realized Disk 100% usage for very long time was unusual. Here is solution to solve this issue.

1. Press Windows + R and type “services.msc”

Services.msc

2. Disable BITS

Right click on BITS and select “Properties”:

Capture

Disable it by :

Capture

Reboot and you can see that disk usage back to normal!

,

Django

Setup Ubuntu For Django Development

7 Sep , 2014  

Here is tutorial to setup Ubuntu for Django development. Fyi, i use Lubuntu instead of Ubuntu since it’s very lightweight and fast! I really recommend it for you if nice UI is not your problems.

1. Install dependecies

1
2
sudo apt-get install vim git python2.7 python-dev python-software-properties python-pip
sudo apt-get install libpq-dev python-dev postgresql postgresql-contrib libxml2 libxml2-dev libxslt1-dev libbz2-dev libssl-dev p7zip-full rar unrar unzip unace unp bzip2 gzip patch

2. Install Java

1
2
3
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

3. Remove crash apport

1
2
sudo rm -rf /var/crash
sudo vim /etc/default/apport

Change from 1 into 0 to disable apport

4. Download AptanaStudio 3 and make launcher

1
2
3
sudo mv Aptana_Studio_3 /opt
wget http://www.samclarke.com/wp-content/uploads/2012/04/AptanaStudio3.desktop
sudo mv AptanaStudio3.desktop /usr/share/applications/AptanaStudio3.desktop

5. Setup Django development

1
sudo apt-get install apache2 phpmyadmin

Uncategorized

Good Wording For Meeting

5 Sep , 2014  

I found this gem in linkedin https://www.linkedin.com/today/post/article/20140903114939-6526187-beware-these-tricks-for-making-you-look-bad-in-meetings

Regional Vice President – Field Supervision at Royal Alliance Associates INC

Let me try to add a little positivity to some of these examples. I personally know people who feel the way the author describes in the article but I honestly have to say that I would consider these people the problem, not the language used with them.

1. “I don’t need all the details. Let’s just get to the bottom line.” – I ‘m not listening —Or maybe I trust you judgement, in the interest of everyones time please give me the important info.

2. “Well, these are the facts.” – I know more than you. — In the interest of time and/or based on the research I or someone else has already completed, here are the important points.

3. “You might be right.” – I don’t think you are right until I verify it for myself. —-May you are right… here is some more info to consider.

4. “I’m wondering about ____. Pat, please get back to us on this.” – You do the work, I’ll take the credit (if it’s Pat’s job or if he is the subject matter expert, this would make sense).

5. “You did a great job on that, Pat!” – I’m happy to give you MY approval —I’m really appreciative of the work you did. (silly to think you can’t give a peer or even a more senior person a compliment).

6. “I think what Pat is trying to say is…” – Thanks for trying, I’ll take it from here (if this is done in the right context there shouldn’t be any issues, sometimes someone else may say it better, or maybe just better for the current audience)

7. “I can see why you might think that.” Variant: “I used to think that, too.” –Then I evolved —-I used to think that too, I learned….. which is what changed my opinion. Or maybe there is more to consider now and special circumstances not widely known.