Hello,
I am pretty new to django and python and stuck with admin interface
functionality.
I have a model which represents a product, and I want to have
functionality to add product via admin interface with picture and
later to have possibility to update it using the same admin
interface.
The problem is then I am updating the product data, if no file has
been uploaded, then file field becomes empty!
How do I rewrite save() method to stop it reseting image field, but
update it only when it is uploaded?
My current Product model:
---------------------------------------
class Product(db.Model):
title = db.StringProperty(required=True)
description = db.StringProperty()
price = db.FloatProperty()
image = db.BlobProperty()
created = db.DateTimeProperty(auto_now_add = True)
lastmodified = db.DateTimeProperty(auto_now = True)
def save(self):
if getattr(self, 'image'):
img = getattr(self, 'image')
print "String length: " + len(img)
image = images.resize(getattr(self, 'image'), settings.THW2,
settings.THT2)
setattr(self, 'image', image)
super(Product, self).save()
--------------------------------------------
I have tried to apply some changes on save method and update seems to
be working as expected and not able to creat new products anymore:
--------------------------------------------
class Product(db.Model):
title = db.StringProperty(required=True)
description = db.StringProperty()
price = db.FloatProperty()
image = db.BlobProperty()
created = db.DateTimeProperty(auto_now_add = True)
lastmodified = db.DateTimeProperty(auto_now = True)
def save(self):
Product.title = getattr(self, 'title')
Product.description = getattr(self, 'description')
Product.price = getattr(self, 'price')
if getattr(self, 'image'):
Product.image = images.resize(getattr(self, 'image'),
settings.THW2, settings.THT2)
#strange, why does it update record without calling save() ???
#super(Product, self).save()
---------------------------------------------
Woud be grateful for your help!
Thanks,
Andrew
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---