Re: accessing a model ojbect's saved fields
To add more detail: The db version of the file won't be removed until the save method is complete. def save(self): if self.id: #The photo currently exists m = MyModel.objects.get(pk=self.id) if m.photo == self.photo: #They are the same photo else: #They are not the same photo I hope this helps. On Jul 9, 8:04 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Wed, 2008-07-09 at 17:02 +0200, KONTRA, Gergely wrote: > > > Could you override the save method and remove the file from the > > > filesystem prior to saving? > > > That's what I'm attempting to. > > BUT: > > the question is: how can I figure out the database-saved value of the photo > > > class MyModel(models.Model): > > photo = ImageField(upload_to='temp') > > def save(self): > > if self.id: > > # now self.photo points to the requested image being > > uploaded in the admin, not the previously saved one > > You'll have to ask the database for the previous value. Django doesn't > store the "changed value" like this. One day, maybe. Right now, no. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: accessing a model ojbect's saved fields
On Wed, 2008-07-09 at 17:02 +0200, KONTRA, Gergely wrote: > > Could you override the save method and remove the file from the > > filesystem prior to saving? > > That's what I'm attempting to. > BUT: > the question is: how can I figure out the database-saved value of the photo > > class MyModel(models.Model): > photo = ImageField(upload_to='temp') > def save(self): > if self.id: > # now self.photo points to the requested image being > uploaded in the admin, not the previously saved one You'll have to ask the database for the previous value. Django doesn't store the "changed value" like this. One day, maybe. Right now, no. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: accessing a model ojbect's saved fields
> Could you override the save method and remove the file from the > filesystem prior to saving? That's what I'm attempting to. BUT: the question is: how can I figure out the database-saved value of the photo class MyModel(models.Model): photo = ImageField(upload_to='temp') def save(self): if self.id: # now self.photo points to the requested image being uploaded in the admin, not the previously saved one > > e.g. > > class MyModel(models.Model): >... > >def save(self): >if self.id: # is a record in the database ># file system unlink call to self.path >super(MyModel, self).save() > > -Rob > > On Jul 9, 6:22 am, pihentagy <[EMAIL PROTECTED]> wrote: >> Hi all! >> >> Is it possible to access a model object's saved field values? >> Purpose: >> I have an ImageField, and if that field changes, I would like to >> remove the old file from the filesystem. Now the only way to figure it >> out is with a new query, but I suspect this hits the database again, >> and seems a bit hacky BTW. >> >> thanks >> Gergo -- EB White - "Be obscure clearly." --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: accessing a model ojbect's saved fields
Could you override the save method and remove the file from the filesystem prior to saving? e.g. class MyModel(models.Model): ... def save(self): if self.id: # is a record in the database # file system unlink call to self.path super(MyModel, self).save() -Rob On Jul 9, 6:22 am, pihentagy <[EMAIL PROTECTED]> wrote: > Hi all! > > Is it possible to access a model object's saved field values? > Purpose: > I have an ImageField, and if that field changes, I would like to > remove the old file from the filesystem. Now the only way to figure it > out is with a new query, but I suspect this hits the database again, > and seems a bit hacky BTW. > > thanks > Gergo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~--~~~~--~~--~--~---