#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from django.db import models
from django.utils.translation import ugettext_lazy as _

from opps.core.models import Publishable
from opps.db import Db


NOTIFICATION_TYPE = (
    (u'json', _(u'JSON')),
    (u'text', _(u'Text')),
    (u'html', _(u'HTML')),
)


class Notification(Publishable):
    container = models.ForeignKey('containers.Container')
    action = models.CharField(_('Action'), max_length=75,
                              default="message")
    type = models.CharField(_('Type'), max_length=10,
                            choices=NOTIFICATION_TYPE,
                            type='json')
    message = models.TextField(_('Message'))

    def add(self, container, message, action='message', _type='json',
            **attrs):
        notification = Notification.objects.create(
            container=container,
            action=action,
            type=_type,
            message=message,
            **attrs
        )

        _db = Db(notification.container.get_absolute_url(),
                 notification.container.id)
        _db.publish(json.dumps({
            "action": notification.action,
            "id": notification.id,
            "published": notification.published,
            "date": notification.date_available,
            "message": notification.message}))

@@ -716,317 +716,58 @@
 def 
-add
+save
 (self, 
-container, message, action='message', _type='json',%0A            **attrs):%0A        notification = Notification.objects.create(%0A            container=container,%0A            action=action,%0A            type=_type,%0A            message=message,%0A            **attrs%0A        )%0A%0A        _db = Db(notification
+*args, **kwargs):%0A        _db = Db(self
 .con
@@ -810,28 +810,20 @@
         
-notification
+self
 .contain
@@ -884,28 +884,20 @@
 ction%22: 
-notification
+self
 .action,
@@ -915,28 +915,20 @@
   %22id%22: 
-notification
+self
 .id,%0A   
@@ -949,28 +949,20 @@
 ished%22: 
-notification
+self
 .publish
@@ -985,28 +985,20 @@
 %22date%22: 
-notification
+self
 .date_av
@@ -1033,20 +1033,12 @@
 e%22: 
-notification
+self
 .mes

Update save Notification, save in nosql database