Hey.

I needed a fix to make some (but not all) models in an existing app
delete the previous content of a FileField after update.  I figured
out a workaround, but should I be wary of anything with this
implementation, or is there a better way to do it?

Thanks.

-Mick.

from djano.contrib.contenttypes.models import Model

class OrderedModel(Model):
     dev save(self):
          # Some custom save code to facilitate ordering

class  FileReplacerMixin():
     def save(self):
          # Code to check each FileField for changes and delete as
appropriate.

# Now I can have Ordered or Unordered models which
# either replace files or keep the previous content around, such as:

class OrderedModelWhichReplacesFiles(OrderedModel, FileReplacerMixin):
     def save(self):
          # Call the mix-in to replace files
          FileReplacerMixin(self)
          # Call the parent class's save function
          super (OrderedModelWhichReplacesFiles, self).save()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to