Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8600529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:38:15+00:00 2026-06-12T01:38:15+00:00

I want to write the Manager of a Model into the Model-class itself. class

  • 0

I want to write the Manager of a Model into the Model-class itself.

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)

But I get the following error:

Traceback (most recent call last):
  File "C:\Users\niklas\Desktop\blog_project\manage.py", line 10, in <module>
    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 <module>
    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)

Can you tell me why this error occurs and if what I want to do is even possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:38:17+00:00Added an answer on June 12, 2026 at 1:38 am

    It looks like you can’t, this is a bug in Django, you can report it 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want write a little code analyzer which parses nested structures and translates into
I want to write a class with three int values in them and manipulate
I use Backbone.js to create a web app,all the view,collection and model write into
I want to write something like file manager, but don't understand how get begin
I have two classes, Portfolio, and PortfolioImage. class PortfolioImage(models.Model): portfolio = models.ForeignKey('Portfolio', related_name='images') ...
I want to write a unit test for a Django manage.py command that does
I want write a simple query which will fetch data from a table (which
Hello I want write my own desktop sharing application in Java. The application should
I want to write a batch script statement where: FINDSTR has to check for
I want to write a program in Prolog that confirms if a b-tree of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.