To what advantages can I override the model methods in django?
I know you can override the model methods but I was curious as to What all is possible is through this ?
Also another questio开发者_开发技巧n if people want to answer ->
I wanted to design security checks, whenever anybody is updating and/or deleting from a model. Is it advisable to implement these somehow in the model methods or is it better to keep this logic in the views?
I know you can override the model methods but I was curious as to What all is possible is through this ?
Sometimes you need it. What if you need to do something else other than db operation while saving and deleting?
For example, you have a model with ImageField/FileField. You'll want to override their save and delete (save the image/file to the disk when adding rows to the db, and delete them when deleting rows)
I wanted to design security checks, whenever anybody is updating and/or deleting from a model. Is it advisable to implement these somehow in the model methods or is it better to keep this logic in the views?
I dont know about your security checks. However, it's common to define custom methods on your model for row level functionality, and on your Manager (django.db.models.Manager) for table functionality.
the process to get models added/updated/deleted = view code
the nitty gritty (internal) of adding/updating/deleting models = model or manager code
EDIT: formatting
精彩评论