Tuesday, March 17, 2009

"reset is not a function" - Firebug error

I am a newbee to javascripting and I was stuck at reseting a form to default values for 2 full days..


Firebug kept saying
$("#addpropertyForm")[0].reset is not a function

Turned out that I had named the reset button as reset...!!
input type="reset" name="reset".....

Friday, March 13, 2009

Django serialization - Deserialization

I have a table
desc property;
+--------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------+------+-----+---------+----------------+
| property_id | int(11) | NO | PRI | NULL | auto_increment |
| property_name | varchar(30) | NO | | NULL | |
| property_address_1 | varchar(120) | NO | | NULL | |
| property_address_2 | varchar(120) | YES | | NULL | |
| property_city | varchar(30) | NO | | NULL | |
| property_state | varchar(30) | NO | | NULL | |
| property_pincode | int(7) | NO | | NULL | |
| property_country | varchar(30) | NO | | NULL | |
| property_user_id | int(11) | NO | MUL | NULL | |
| property_price | int(20) | NO | | NULL | |
+--------------------+--------------+------+-----+---------+----------------+

Serialize

python manage.py shell
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
>>> from users.models import Property
>>> from django.core import serializers

>>> json = serializers.serialize("json", Property.objects.filter(pk=2)
>>> print json
[{"pk": 1, "model": "users.property", "fields": {"property_user_id": 1, "property_state": "aa", "property_country": "aa", "property_pincode": 323, "property_city": "aa", "property_price": 1, "property_address_1": "aa", "property_name": "aa", "property_address_2": "aa"}}]



Deserialize
>>> json = '[{"pk": 2, "model": "users.property", "fields": {"property_user_id": 2, "property_state": "aa", "property_country": "aa", "property_pincode": 323, "property_city": "aa", "property_price": 1, "property_address_1": "aa", "property_name": "aa", "property_address_2": "aa"}}]'

>>> for obj in serializers.deserialize("json", json):
... obj.save()


I finally dint use it because I dint know how to convert a UTF encoded dictionary to string.. shame on me..!!

Wednesday, March 11, 2009

foreign key across different mysql engines

I had a pre existing table(MYISAM) and I was creating new table innodb.
Dint realize for a long time that you cant have a foreign key relationship across 2 tables of different engines.
Error that you would see are

mysql> alter table property add (FOREIGN KEY(id) REFERENCES AUTH_USER(id));
ERROR 1005 (HY000): Can't create table 'sportland.#sql-134d_a' (errno: 150)
mysql> show engine innodb status;
------------------------
LATEST FOREIGN KEY ERROR
------------------------
090311 15:36:27 Error in foreign key constraint of table sportland/#sql-134d_a:
FOREIGN KEY(id) REFERENCES AUTH_USER(id)):
Cannot resolve table name close to:
(id))

took me sometime to figure out the issue..!!