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
=True)
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()
40 "select reltuples from pg_class where relname='%s';"
41 % self
.model
._meta
.db_table
43 row
= cursor
.fetchone()
47 class UpdateInfoModel(models
.Model
):
48 """Model that keeps track of when it was created and updated"""
50 created
= models
.DateTimeField(auto_now_add
=True)
51 modified
= models
.DateTimeField(auto_now
=True)
57 class DeleteableModel(models
.Model
):
58 """A model that can be marked as deleted"""
60 # indicates that the object has been deleted
61 deleted
= models
.BooleanField(default
=False)
67 class OrderedModel(models
.Model
):
68 """A model that can be ordered
70 The implementing Model must make sure that 'order' is sufficiently unique
73 order
= models
.PositiveSmallIntegerField()
80 class OptionallyOrderedModel(models
.Model
):
81 """A model that can be ordered, w/ unknown order of individual objects
83 The implementing Model must make sure that 'order' is sufficiently unique
86 order
= models
.BigIntegerField(null
=True, default
=None)