# coding=utf-8
from django.db import models


# basic model stuff
##########################################
from django.db.models import Sum
from django.forms import forms
from django.utils.datetime_safe import datetime


class DataManager(models.Manager):

    def get_query_set(self):
        qs = super(DataManager, self).get_query_set()
        return qs.filter(active=True)
        
    def delete(self):
        self.update(active=False)


class AllObjectsManager(models.Manager):

    def deleted(self):
        return self.filter(active=False)


# base model with useful stuff
class BaseModel(models.Model):

    created = models.DateTimeField(auto_now_add=True, editable=False)
    modified = models.DateTimeField(auto_now=True, editable=False)
    deleted = models.DateTimeField(editable=False, null=True)

    active = models.BooleanField(default=True, editable=False)

    # access only active data objects
    data = DataManager()
    # access all (including deleted) data (active is false)
    objects = AllObjectsManager()

    class Meta:
        abstract = True
        ordering = ['-created']

    # deleted data is bad - doing it you shouldn't!
    def delete(self, using=None):
        self.active = False
        self.save()

    def save(self, force_insert=False, force_update=False, using=None,
             update_fields=None):

        if self.active:
            self.deleted = None
        else:
            self.deleted = datetime.now()

        super(BaseModel, self).save(force_insert=force_insert, using=using,
                                    update_fields=update_fields)

    def reload_me(self):
        if self.id:
            return self.__class__.objects.get(id=self.id)


class NamedModel(models.Model):
    name = models.CharField('Name', max_length=150)

    class Meta:
        ordering = ['name']
        abstract = True

    def __unicode__(self):
        return self.name


@@ -41,184 +41,382 @@
 els%0A
-%0A%0A# basic model stuff%0A##########################################%0Afrom django.db.models import Sum%0Afrom django.forms import forms%0Afrom django.utils.datetime_safe import datetime
+from django.db.models.query import QuerySet%0Afrom django.utils.datetime_safe import datetime%0A%0A# basic model stuff%0A##########################################%0Aclass DataQuerySet(QuerySet):%0A    def delete(self):%0A        self.update(active=False, deleted=datetime.now())%0A%0A%0Aclass AllObjectsQuerySet(QuerySet):%0A    def undelete(self):%0A        self.update(active=True, deleted=None)
 %0A%0A%0Ac
@@ -440,32 +440,66 @@
 models.Manager):
+%0A    use_for_related_fields = True
 %0A%0A    def get_qu
@@ -530,47 +530,47 @@
 s = 
-super(DataManager, self).get_query_set(
+DataQuerySet(self.model, using=self._db
 )%0A  
@@ -605,24 +605,16 @@
 e=True)%0A
-        
 %0A    def
@@ -656,24 +656,48 @@
 active=False
+, deleted=datetime.now()
 )%0A%0A%0Aclass Al
@@ -726,24 +726,110 @@
 .Manager):%0A%0A
+    def get_query_set(self):%0A        return DataQuerySet(self.model, using=self._db)%0A%0A
     def dele
@@ -1009,24 +1009,39 @@
 itable=False
+, db_index=True
 )%0A    modifi
@@ -1091,24 +1091,39 @@
 itable=False
+, db_index=True
 )%0A    delete
@@ -1236,16 +1236,31 @@
 le=False
+, db_index=True
 )%0A%0A    #
@@ -1616,24 +1616,108 @@
 elf.save()%0A%0A
+    def undelete(self, using=None):%0A        self.active = True%0A        self.save()%0A%0A
     def save
@@ -1774,29 +1774,16 @@
 ng=None,
-%0A            
  update_
@@ -2170,31 +2170,28 @@
  NamedModel(
-models.
+Base
 Model):%0A    
@@ -2236,16 +2236,31 @@
 ngth=150
+, db_index=True
 )%0A%0A    c
@@ -2375,9 +2375,8 @@
 lf.name%0A
-%0A

Update models.py