Within a Django Model, how can I prevent a delete based on a particular field?
问题 In the following, I have a Post model. A Post object has a status field that can be 'unpublished' or 'published' . if status is 'published' , I'd like to prevent the object from being deleted, and would like to keep this logic encapsulated in the model itself. from model_utils import Choices # from Django-Model-Utils from model_utils.fields import StatusField class Post(model.Models) STATUS = Choices( ('unpublished', _('Unpublished')), ('published', _('Published')), ) ... status = StatusField