src/notes/models/base.py
author ymh <ymh.work@gmail.com>
Mon, 24 Jul 2017 16:58:34 +0200
changeset 126 ba8bc0199464
parent 119 8ff8e2aee0f9
permissions -rw-r--r--
add log api for syncing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
"""
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
base abstract models
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
"""
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
import uuid
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
from concurrency.fields import AutoIncVersionField
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
from django.db import models
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
from django.utils.translation import ugettext_lazy as _
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
class ModelManager(models.Manager):
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    def get_by_natural_key(self, ext_id):
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
        return self.get(ext_id=ext_id)
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
class Model(models.Model):
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    objects = ModelManager()
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
119
8ff8e2aee0f9 add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
    18
    created = models.DateTimeField(auto_now_add=True, verbose_name=_('Model|created'), db_index=True)
8ff8e2aee0f9 add parameter to filter session and note by updated date. Add pagination on sessions and notes. add read only endpoint at root level to list notes
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
    19
    updated = models.DateTimeField(auto_now=True, verbose_name=_('Model|updated'), db_index=True)
24
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    ext_id = models.UUIDField(unique=True, default=uuid.uuid4, verbose_name=_('Model|ext_id'))
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    version = AutoIncVersionField(verbose_name=_('Model|version'))
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    def natural_key(self):
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
        return (self.ext_id, )
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    class Meta:
3b3999550508 first data model for backend
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
        abstract = True