在 Django 中有一个 SingletonModel 怎么样? [英] How about having a SingletonModel in Django?

查看:32
本文介绍了在 Django 中有一个 SingletonModel 怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Django 制作一个非常简单的网站.在其中一页上有一个垂直的代码框.我需要给客户端一种方法来编辑股票代码框的内容作为 HTMLField.

I'm making a very simple website in Django. On one of the pages there is a vertical ticker box. I need to give the client a way to edit the contents of the ticker box as an HTMLField.

想到的第一种方法是制作一个只有一个实例的模型 Ticker.然后我想,与其手动确保只有一个实例存在,不如在 Django 中存在(或应该存在)类似 SingletonModel 类的东西,它就像一个普通模型,只是它确保创建的实例不超过一个?

The first way that came to mind was to make a model Ticker which will have only one instance. Then I thought, instead of making sure manually that only one instance exists, perhaps there is (or there should be) something like a SingletonModel class in Django, which is like a normal model, except it makes sure no more than one instance gets created?

或许我应该以不同的方式解决我的问题?

Or perhaps I should be solving my problem in a different way?

推荐答案

尝试 django-solo,它肯定适用于 django 1.5 +,django-singletons 不适用于 1.5 +,因为它使用了一个已弃用的功能.

Try django-solo, it works in django 1.5 + for sure, django-singletons doesn't work with 1.5 + because it uses a deprecated feature.

这篇关于在 Django 中有一个 SingletonModel 怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆