dj-myghanta is a Django app to allow end users to create timestamp model field for MySQL.
-
Install it through pip
pip install dj-myghanta
-
Download and install manually
git clone https://github.com/paytm/dj-myghanta.git cd dj-myghanta python setup.py install
-
Add
myghanta
in yourINSTALLED_APPS
likeINSTALLED_APPS = ( ... 'myghanta', )
-
Now import it in your models like
from myghanta.fields import MysqlTimeStampField
-
Create fields like
# auto_now_add = True creates `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP created_at = MysqlTimestamp(auto_now_add=True) # auto_now = True creates `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP updated_at = MysqlTimestamp(auto_now=True)
- Works only for Mysql . Tested on mysql 5.6, 5.7