Would there be a way to do something like this:

If contrib.contenttypes are in settings.INSTALLED_APPS:
   Add to models.Model a method:
   get_content_type that returns the ContentType object?.

That way, any model I have will have that method available to easily and
quickly get its content type.

I've been playing with apps that relate to content types more and this
seems like a useful thing to have.

I tried adding a method to my model along the lines of this:

     def get_content_type(self):
         cm = ContentTypeManager()
         return cm.get_for_model(self)

But that failed:

>>> from innovate.innovation.models import Innovation
>>> i = Innovation.objects.get(id=1)
>>> i.get_content_type()
Traceback (most recent call last):
   File "<console>", line 1, in ?
   File
"/Users/rhudson/sandbox/innovate/../innovate/innovation/models.py", line
37, in get_content_type
     return cm.get_for_model(self)
   File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/django/contrib/contenttypes/models.py",
 

line 13, in get_for_model
     ct, created =
self.model._default_manager.get_or_create(app_label=opts.app_label,
AttributeError: 'NoneType' object has no attribute '_default_manager'

So I ended up hard coding it, which is ok, I suppose:

    def get_content_type(self):
         return ContentType.objects.get(app_label__exact="innovation",
model__exact="innovation")

It just seems like a more introspective way to do this could come in handy.

-Rob


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to