Skip to content

Instantly share code, notes, and snippets.

@theskumar
Created May 3, 2015 09:37
Show Gist options
  • Save theskumar/11ef947c44e252127923 to your computer and use it in GitHub Desktop.
Save theskumar/11ef947c44e252127923 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
# Standard Library
import uuid
# Third Party Stuff
from django.db import models
from django_extensions.db.models import TimeStampedModel
class UUIDModel(models.Model):
'''
An abstract base class model that makes primary key `id` as UUID
instead of default auto incremented number.
'''
id = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4)
class Meta:
abstract = True
class TimeStampedUUIDModel(TimeStampedModel, UUIDModel):
'''
An abstract base class model that provides self-updating
``created`` and ``modified`` fields with UUID as primary_key field.
'''
class Meta:
abstract = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment