Created
August 24, 2012 17:08
-
-
Save rmaceissoft/3452971 to your computer and use it in GitHub Desktop.
generating unique id from datetime field in order to implement infinite scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from django.db import models | |
class MyModel(models.Model): | |
# other fields... | |
start_date = models.DateTimeField() | |
unique_date = models.CharField(max_length=32, unique=True) | |
def save(self, **kwargs): | |
str_timestamp = str(long(time.time() * 1000)) | |
str_start_date = self.start_date.strftime('%Y%m%d%H%M%S') | |
self.unique_date = '%s_%s' % (str_start_date, str_timestamp) | |
super(MyModel, self).save(**kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks @francofuji