﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
1717	[patch] [magic-removal] add content-type back to the model (optionally)	Ian@…	Adrian Holovaty	"The following adds the content type field back to the model.
It only adds it *IF* you have included the contenttypes app in your setting, so it won't affect the minimalist people who don't want content-types at all.



{{{
Index: models.py
===================================================================
--- models.py   (revision 2766)
+++ models.py   (working copy)
@@ -1,5 +1,7 @@
 from django.db import models
+from django.db.models import signals
 from django.utils.translation import gettext_lazy as _
+from django.dispatch import dispatcher 
 
 class ContentTypeManager(models.Manager):
     def get_for_model(self, model):
@@ -47,3 +49,19 @@
         so code that calls this method should catch it.
         """"""
         return self.model_class()._default_manager.get(**kwargs)
+
+class LazyContentType(object):
+    def __init__(self):
+        self._myContentType = None
+#        self._myModel = model
+
+    def __get__(self, cls, obj_type=None):
+        if self._myContentType is None:
+            self._myContentType = ContentType.objects.get_for_model( obj_type )
+        return self._myContentType
+
+
+def add_contenttypes(sender):
+    sender.model_ContentType= LazyContentType()
+
+dispatcher.connect(add_contenttypes, signal=signals.class_prepared)
}}}"	enhancement	closed	Contrib apps		normal	fixed			Unreviewed	1	0	0	0	0	0
