Bump python-dateutil from 2.7.3 to 2.7.4
[mygpo.git] / mygpo / core / models.py
blob8d0b730cdb7c2e891a66c6c9772cd6f223fa92c8
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)
12 class Meta:
13 abstract = True
15 def get_id(self):
16 """ String representation of the ID """
17 return self.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)
25 class Meta:
26 abstract = True
29 class GenericManager(models.Manager):
30 """ Generic manager methods """
32 def count_fast(self):
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()
42 return int(row[0])
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)
50 class Meta:
51 abstract = 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)
60 class Meta:
61 abstract = True
64 class OrderedModel(models.Model):
65 """ A model that can be ordered
67 The implementing Model must make sure that 'order' is sufficiently unique
68 """
70 order = models.PositiveSmallIntegerField()
72 class Meta:
73 abstract = True
74 ordering = ['order']
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
81 """
83 order = models.BigIntegerField(null=True, default=None)
85 class Meta:
86 abstract = True
87 ordering = ['order']