Ver Mensaje Individual
  #4 (permalink)  
Antiguo 19/05/2012, 17:23
Avatar de _cronos2
_cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 11 meses
Puntos: 310
Respuesta: [Django] Crear notificación al guardar objeto en la DB

Gracias a los dos por vuestras respuestas. Al final me he decantado por la solución de @snahor_ pero modificándola un poco para acomodarse a mis necesidades. Dejo la solución:
Código Python:
Ver original
  1. class Insert():
  2.     '''
  3.    Abstract class for models which need to do some stuff when are created, but only then (INSERT)
  4.    '''
  5.    
  6.     def save(self, *args, **kwargs):
  7.         exists = self.pk
  8.         models.Model.save(self, *args, **kwargs) # since we can't use super, use models.Model.save directly
  9.                                                 # and pass it <self> (Model inherits from models.Model)
  10.        
  11.         if self.__insert__ and not exists:
  12.             self.__insert__(*args, **kwargs)
  13.        
  14.         models.Model.save(self) # save it again to keep the __insert__ changes
  15.  
  16. class Foo(Insert, models.Model):
  17.     pass
Saludos (:
__________________
" Getting older’s not been on my plans
but it’s never late, it’s never late enough for me to stay. "
Cigarettes - Russian Red