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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:05:21+00:00 2026-05-30T16:05:21+00:00

I have a model that I want to save in Django Admin class Product(models.Model):

  • 0

I have a model that I want to save in Django Admin

class Product(models.Model):
    # other fields
    img1 = models.ImageField(upload_to='%s/%s/1/large/' % (category, prod_no))
    img1_thumb = models.ImageField(upload_to='%s/%s/1/thumbnail/' % (category, prod_no), editable=False)

    def save(self, *args, **kwargs):
        newImg1  = resizeImg(self.img1, (75, 112))
        self.img1_thumb = newImg1
        super(Product, self).save(*args, **kwargs)

The resize image function

def resizeImg(image, size):
    try:
        if imghdr.what(image) == 'jpeg':
            img = Image.open(image)
            img.thumbnail(size, Image.ANTIALIAS)

            # this is how to save the img
            # img.save(filename + '.jpg', 'JPEG', quality=75)

            return img
        else:
            return 'not_jpg'

    except Exception, e:
        return 'exception'

Saving this in Django Admin creates this error

AttributeError at /admin/myapp/product/add/
_committed

UPDATE – full traceback:

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/admin/myapp/product/add/

Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'bc']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.csrf.CsrfResponseMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in wrapper
  307.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  79.         response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in inner
  197.             return view(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapper
  28.             return bound_func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in bound_func
  24.                 return func(self, *args2, **kwargs2)
File "/Library/Python/2.7/site-packages/django/db/transaction.py" in inner
  217.                 res = func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in add_view
  882.                 self.save_model(request, new_object, form, change=False)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in save_model
  665.         obj.save()
File "/Users/rocky/Projects/BestChoose/bc/models.py" in save
  66.         super(Product, self).save(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save
  460.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save_base
  543.                         for f in meta.local_fields if not isinstance(f, AutoField)]
File "/Library/Python/2.7/site-packages/django/db/models/fields/files.py" in pre_save
  253.         if file and not file._committed:
File "/Library/Python/2.7/site-packages/PIL-1.1.7-py2.7-macosx-10.7-intel.egg/Image.py" in __getattr__
  512.         raise AttributeError(name)

Exception Type: AttributeError at /admin/myapp/product/add/
Exception Value: _committed
  • 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-30T16:05:23+00:00Added an answer on May 30, 2026 at 4:05 pm

    You cannot do this:

    newImg1  = resizeImg(self.img1, (75, 112))
    self.img1_thumb = newImg1
    

    You are assigning an Image to a field that expects a File. You need to first create a file from the image. Instead of typing it all out again, please see this snippet that details the right way.

    You can also use any of the thumbnailing applications available to simplify your code. solr-thumbnail is one of the most popular.

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

Sidebar

Related Questions

I have a model that contains one-to-one fields to other models. I over rid
I have a Django model that looks something like this: class Person(models.Model): name =
I want to have a model with calculated fields that I can apply sorting
I have a model that is something like this: class Input(models.Model): details = models.CharField(max_length=1000)
Let's assume that I have following models: class ScoutBook(models.Model): troop = models.ForeignKey('Dictionary', limit_choices_to={'type' :
A noob here. I have a model class where I want to save something
I have a Django model which looks like this: class MyModel(models.Model): parent = models.ForeignKey(ParentModel)
I have a Comment model that I want people to be able to save
I have a simple model that is defined as: class Article(models.Model): slug = models.SlugField(max_length=50,
Right now, I have more than 25 vertices that form a model. I want

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.