1 """ This module contains abstract models that are used in multiple apps """
3 from __future__
import absolute_import
, unicode_literals
7 from uuidfield
import UUIDField
9 from django
.db
import models
, connection
12 class UUIDModel(models
.Model
):
13 """ Models that have an UUID as primary key """
15 id = UUIDField(primary_key
=True)
21 """ String representation of the ID """
25 class TwitterModel(models
.Model
):
26 """ A model that has a twitter handle """
28 twitter
= models
.CharField(max_length
=15, null
=True, blank
=False)
34 class GenericManager(models
.Manager
):
35 """ Generic manager methods """
38 """ Fast approximate count of all model instances
40 PostgreSQL is slow when counting records without an index. This is a
41 workaround which only gives approximate results. see:
42 http://wiki.postgresql.org/wiki/Slow_Counting """
43 cursor
= connection
.cursor()
44 cursor
.execute("select reltuples from pg_class where relname='%s';" %
45 self
.model
._meta
.db_table
)
46 row
= cursor
.fetchone()
50 class UpdateInfoModel(models
.Model
):
51 """ Model that keeps track of when it was created and updated """
52 created
= models
.DateTimeField(auto_now_add
=True)
53 modified
= models
.DateTimeField(auto_now
=True)
59 class DeleteableModel(models
.Model
):
60 """ A model that can be marked as deleted """
62 # indicates that the object has been deleted
63 deleted
= models
.BooleanField(default
=False)
69 class OrderedModel(models
.Model
):
70 """ A model that can be ordered
72 The implementing Model must make sure that 'order' is sufficiently unique
75 order
= models
.PositiveSmallIntegerField()