1 """ This module contains abstract models that are used in multiple apps """
4 from django
.db
import models
, connection
7 class UUIDModel(models
.Model
):
8 """ Models that have an UUID as primary key """
10 id = models
.UUIDField(primary_key
=True)
16 """ String representation of the ID """
20 class TwitterModel(models
.Model
):
21 """ A model that has a twitter handle """
23 twitter
= models
.CharField(max_length
=15, null
=True, blank
=False)
29 class GenericManager(models
.Manager
):
30 """ Generic manager methods """
33 """ Fast approximate count of all model instances
35 PostgreSQL is slow when counting records without an index. This is a
36 workaround which only gives approximate results. see:
37 http://wiki.postgresql.org/wiki/Slow_Counting """
38 cursor
= connection
.cursor()
39 cursor
.execute("select reltuples from pg_class where relname='%s';" %
40 self
.model
._meta
.db_table
)
41 row
= cursor
.fetchone()
45 class UpdateInfoModel(models
.Model
):
46 """ Model that keeps track of when it was created and updated """
47 created
= models
.DateTimeField(auto_now_add
=True)
48 modified
= models
.DateTimeField(auto_now
=True)
54 class DeleteableModel(models
.Model
):
55 """ A model that can be marked as deleted """
57 # indicates that the object has been deleted
58 deleted
= models
.BooleanField(default
=False)
64 class OrderedModel(models
.Model
):
65 """ A model that can be ordered
67 The implementing Model must make sure that 'order' is sufficiently unique
70 order
= models
.PositiveSmallIntegerField()
77 class OptionallyOrderedModel(models
.Model
):
78 """ A model that can be ordered, w/ unknown order of individual objects
80 The implementing Model must make sure that 'order' is sufficiently unique
83 order
= models
.BigIntegerField(null
=True, default
=None)