[Django]-How about having a SingletonModel in Django?

11👍

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.

3👍

You can use django_singletons. It has a built in admin support.

👤aabele

2👍

I think having a “singleton” model is ugly; it’s dumb use of the relational database and it’s bad UI, because the admin UI is built around working with lists of objects.

Instead I prefer to use a generic solution like django-chunks or django-flatblocks for this.

1👍

rewrite your save method so that every time a Ticker object gets saved it overwrites the existing one (if one exists).

1👍

A model with only one instance, a singleton, is sometime useful for things like global settings that you want to edit from the admin instead of having them in Django settings.py.

There are several third party applications that helps implementing singleton models and improve the admin interface for instance, django-solo, django-singleton-admin, django-singletons.

Leave a comment