Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

add year to id django

import datetime
from uuid import uuid4
def create_id():
    now = datetime.datetime.now()
    return str(now.year)+str(now.month)+str(now.day)+str(uuid4())[:7]
  
# in your model:
id = models.CharField(primary_key=True, default=create_id, editable=False)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #add #year #id #django
ADD COMMENT
Topic
Name
2+8 =