Answers for "add year to id django"

1

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)
Posted by: Guest on July-06-2020

Python Answers by Framework

Browse Popular Code Answers by Language