[Answer]-Best practice for static page elements in django

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/

-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.

Leave a comment