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 6818201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:08:58+00:00 2026-05-26T21:08:58+00:00

I have been following along with the book Practical Django Projects. Very nice book,

  • 0

I have been following along with the book Practical Django Projects. Very nice book, but it seem to have a lot of bugs. Luckily this website has some fixes: https://bitbucket.org/philgyford/practical-django-projects/src. My latest error is: save() got an unexpected keyword argument 'force_insert'

The original code was:

class Snippet(models.Model):
    title = models.CharField(max_length=255)
    language = models.ForeignKey(Language)
    author = models.ForeignKey(User)
    description = models.TextField()
    description_html = models.TextField(editable=False)
    code = models.TextField()
    highlighted_code = models.TextField(editable=False)
    pub_date = models.DateTimeField(editable=False)
    updated_date = models.DateTimeField(editable=False)
    objects = managers.SnippetManager()
    tags = TagField()

    class Meta:
        ordering = ['-pub_date']

    def __unicode__(self):
        return self.title

    def save(self, force_insert=False, force_update=False):
        if not self.id:
            self.pub_date = datetime.datetime.now()
        self.updated_date = datetime.datetime.now()
        self.description_html = markdown(self.description)
        self.highlighted_code = self.highlight()
        super(Snippet, self).save(force_insert, force_update)

    @models.permalink
    def get_absolute_url(self):
        return ('cab_snippet_detail', (), { 'object_id': self.id })

    def highlight(self):
        return highlight(self.code,
                         self.language.get_lexer(),
                         formatters.HtmlFormatter(linenos=True))

# See http://blog.sveri.de/index.php?/categories/2-Django
tagging.register(Snippet, tag_descriptor_attr='etags')

I changed the save method (trying to get rid of the error) to:

   def save(self, *args, **kwargs):
      if not 'force_insert' in kwargs:
         kwargs['force_insert'] = False
      if not 'force_update' in kwargs:
         kwargs['force_update'] = False
      # del kwargs['force_insert']
      if not self.id:
         self.pub_date = datetime.datetime.now()
      self.updated_date = datetime.datetime.now()
      self.description_html = markdown(self.description)
      self.highlighted_code = self.highlight()
      super(Snippet, self).save(*args, **kwargs)

I even tried uncommenting the # del bit, which also does not help. Im’m using Django 1.3.1. Any ideas why I’m getting this error?

  • 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-05-26T21:08:58+00:00Added an answer on May 26, 2026 at 9:08 pm

    The second version of your save override should be fine, though I would get rid of the two if statements and the del line.

    If it still doesn’t work, make sure you the development server is actually reloading the models.py file. The quickest way is to CTRL+C the running one and then call python manage.py runserver again. Although it shouldn’t matter, you might want to also get rid of models.pyc as well (compiled version of models.py), just to be extra sure that the new code is running.

    While Practical Django Projects is an excellent book overall, it’s very outdated at this point. You might want to look for newer resources to learn from.

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

Sidebar

Related Questions

I've been following along with this excellent asio tutorial , but have got confused
I have been following along with the Aaron Skonnard videos on creating a WCF
I have been trying to use temporary tables along with nhibernate. The following piece
I have been following the answer of this question: How to update existing object
I have been following the usage of JavaScript for the past few years, and
I have been following the following post on using multiple ItemTemplates in a ListView
I have been following mozilla developer network's docs and created a transition for my
I have been following a couple of articles regarding RESTful web services with WCF
I have been following the validation for Entry boxes from here . The code
I have been following the affableBean tutorial from the NetBeans site located here .

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.