Search code examples
djangodjango-modelsdjango-ormreadonly

How can I make a Django model read-only?


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)


Solution

  • 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