From 24f8e94563010623438c5aacc577f00d3042e1e4 Mon Sep 17 00:00:00 2001 From: Joseph Kocherhans Date: Mon, 9 Jan 2006 18:07:01 +0000 Subject: [PATCH] magic-removal: added django.contrib.contenttypes in anticipation for move from django.models.core git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1886 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/contenttypes/__init__.py | 0 django/contrib/contenttypes/models.py | 41 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 django/contrib/contenttypes/__init__.py create mode 100644 django/contrib/contenttypes/models.py diff --git a/django/contrib/contenttypes/__init__.py b/django/contrib/contenttypes/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py new file mode 100644 index 0000000000..2621bbaddc --- /dev/null +++ b/django/contrib/contenttypes/models.py @@ -0,0 +1,41 @@ +from django.db import models +from django.utils.translation import gettext_lazy as _ + +class Package(models.Model): + label = models.CharField(_('label'), maxlength=20, primary_key=True) + name = models.CharField(_('name'), maxlength=30, unique=True) + class Meta: + verbose_name = _('package') + verbose_name_plural = _('packages') + db_table = 'packages' + ordering = ('name',) + + def __repr__(self): + return self.name + +class ContentType(models.Model): + name = models.CharField(_('name'), maxlength=100) + package = models.ForeignKey(Package, db_column='package') + python_module_name = models.CharField(_('python module name'), maxlength=50) + class Meta: + verbose_name = _('content type') + verbose_name_plural = _('content types') + db_table = 'content_types' + ordering = ('package', 'name') + unique_together = (('package', 'python_module_name'),) + + def __repr__(self): + return "%s | %s" % (self.package_id, self.name) + + def get_model_module(self): + "Returns the Python model module for accessing this type of content." + return __import__('django.models.%s.%s' % (self.package_id, self.python_module_name), '', '', ['']) + + def get_object_for_this_type(self, **kwargs): + """ + Returns an object of this type for the keyword arguments given. + Basically, this is a proxy around this object_type's get_object() model + method. The ObjectNotExist exception, if thrown, will not be caught, + so code that calls this method should catch it. + """ + return self.get_model_module().get_object(**kwargs)