I have a following model with an ImageField:
class PublicCategoryManager(models.Manager):
"""
Custom manager for displaying only public categories.
"""
def get_query_set(self):
return super(PublicCategoryManager, self).get_query_set().filter(is_public=True)
class Category(models.Model):
"""
Category for products. Can relate to itself.
"""
name = models.CharField(max_length=200)
parent = models.ForeignKey('self', blank=True, null=True, related_name='child', verbose_name='parent')
image = models.ImageField(blank=True, null=True, upload_to='categories/')
is_public = models.BooleanField(default=True)
...
objects = models.Manager()
public_objects = PublicCategoryManager()
def save(self, force_insert=False, force_update=False):
if not self.date_added:
self.date_added = datetime.now()
...
super(Category, self).save(force_insert, force_update)
it has a following Admin class
class CategoryAdmin(admin.ModelAdmin):
...
save_as = True
save_on_top = True
prepopulated_fields = {"slug": ("name",)}
raw_id_fields = ('parent',)
Image works OK when first saving it. But when re-saving the object (with of without editind any data) from the admin, the data on the imagefield (in db) is erased. When saving the data from python shell everything works OK.
We're using Python 2.5 and the latest SVN version (r9791) of Django.