1👍
Not really, no. You’re describing a singleton pattern, so you might want to implement a singleton model type:
class SingletonModel(models.Model):
class Meta:
abstract = True
def save(self, *args, **kwargs):
self.id = 1
super(SingletonModel, self).save(*args, **kwargs)
def delete(self, *args, **kwargs):
pass
That will ensure that any model that inherits from that class can only ever have one member and that it can’t be deleted. Other than that, I would suggest combining everything into just one model called something like SiteSettings
with fields for header, footer, etc, instead of separate model for each.
1👍
You could use a context processor to add them to the context and use a simple caching mechanism so you don’t have to hit the db every time like, http://eflorenzano.com/blog/2008/11/28/drop-dead-simple-django-caching/
- [Answer]-Python-Django: ImportError: no module named django
- [Answer]-Order object_list with django-profiles
- [Answer]-How to set username in user model to a random string
- [Answer]-Cookie does not show up in Chrome Developer Tools (Django Python)
-1👍
Hard to answer – what exactly are you asking?
You can display these models in your base template. You can use caching to cut down on database calls.
- [Answer]-Django application – store usernames and passwords in a msql database or openldap?
- [Answer]-UnicodeDecodeError with compilemessages django translator
- [Answer]-Django dumpdata writes datetimes as nulls
- [Answer]-Generating standard xml and making request in Python/Django