Skip to content

Instantly share code, notes, and snippets.

@rmaceissoft
Created August 24, 2012 17:08
Show Gist options
  • Save rmaceissoft/3452971 to your computer and use it in GitHub Desktop.
Save rmaceissoft/3452971 to your computer and use it in GitHub Desktop.
generating unique id from datetime field in order to implement infinite scroll
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)
@rmaceissoft
Copy link
Author

thanks @francofuji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment