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 19040 Allow declaring a model Manager class inside the model class rosensteinniklas@… "It is not possible to have a models' Manager-class defined on the models' class-level this way: {{{ class Post(models.Model): title = models.CharField(max_length=50) slug = models.SlugField(max_length=50, blank=True, unique=True) body = models.TextField(blank=True) pub_date = models.DateTimeField(blank=True) mod_date = models.DateTimeField(blank=True) tags = models.ManyToManyField(Tag) class Meta: ordering = ['pub_date'] # Newest first class Manager(models.Manager): def by_slug(self, slug): slug = slug.strip().lower() return self.get(slug=slug) objects = Manager() def __unicode__(self): return self.title def save(self, *args, **kwargs): self.slug = self.slug or generate_slug(self.title) self.pub_date = self.pub_date or timezone.now() self.mod_date = timezone.now() return super(Post, self).save(*args, **kwargs) }}} I got the following error: {{{ Traceback (most recent call last): File ""C:\Users\niklas\Desktop\blog_project\manage.py"", line 10, in execute_from_command_line(sys.argv) File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\core\management\__init__.py"", line 443, in execute_from_command_line utility.execute() File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\core\management\__init__.py"", line 382, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\core\management\base.py"", line 196, in run_from_argv self.execute(*args, **options.__dict__) File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\core\management\base.py"", line 231, in execute self.validate() File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\core\management\base.py"", line 266, in validate num_errors = get_validation_errors(s, app) File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\core\management\validation.py"", line 30, in get_validation_errors for (app_name, error) in get_app_errors().items(): File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\db\models\loading.py"", line 158, in get_app_errors self._populate() File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\db\models\loading.py"", line 64, in _populate self.load_app(app_name, True) File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\db\models\loading.py"", line 88, in load_app models = import_module('.models', app_name) File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\utils\importlib.py"", line 35, in import_module __import__(name) File ""C:\Users\niklas\Desktop\blog_project\blog\models.py"", line 48, in class Post(models.Model): File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\db\models\base.py"", line 99, in __new__ new_class.add_to_class(obj_name, obj) File ""C:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\db\models\base.py"", line 219, in add_to_class value.contribute_to_class(cls, name) TypeError: Error when calling the metaclass bases unbound method contribute_to_class() must be called with Manager instance as first argument (got ModelBase instance instead) }}} " New feature closed Database layer (models, ORM) dev Normal wontfix model manager jelena.kutalovskaja@… Unreviewed 0 0 0 0 0 0