How can I make a Django model read-only?

Ollie Glass picture Ollie Glass · Aug 28, 2012 · Viewed 15.1k times · Source

Is it possible to make a Django model read only? No creating, updating etc.

N.B. this question is different to:

Make a Django model read-only? (this question allows creation of new records)

Whole model as read-only (only concerns the Django admin interface - I'd like the model to be read only throughout the whole app)

Answer

Mikael picture Mikael · Aug 28, 2012

Override the save and delete methods for the model. How are you planning to add objects to your model?

def save(self, *args, **kwargs):
     return

def delete(self, *args, **kwargs):
     return