apps.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:django-herald 作者: worthwhile 项目源码 文件源码
def ready(self):
        from .models import Notification
        from herald import registry

        self.module.autodiscover()

        try:
            # add any new notifications to database.
            for index, klass in enumerate(registry._registry):
                notification, created = Notification.objects.get_or_create(
                    notification_class=klass.get_class_path(),
                    defaults={
                        'verbose_name': klass.get_verbose_name(),
                        'can_disable': klass.can_disable,
                    }
                )

                if not created:
                    notification.verbose_name = klass.get_verbose_name()
                    notification.can_disable = klass.can_disable
                    notification.save()

        except OperationalError:
            # if the table is not created yet, just keep going.
            pass
        except ProgrammingError:
            # if the database is not created yet, keep going (ie: during testing)
            pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号