1👍
✅
You can add class method this way, decorate method with classmethod:
class Sends(models.Model):
...
@classmethod
def delete_entrie(cls, del_id):
cls.objects.filter(id=del_id).delete()
Call it:
Sends.delete_entire(id_)
0👍
There already is a method, delete
, on models in Django.
So your view could look like::
def admin_sends(request):
if request.method == 'POST':
post = request.POST
Sends.objects.get(id=post['delete']).delete()
...
Meaning “get the object with the matching ID and call the delete method on it.”
- [Answer]-Deny deletion of model if it is referenced in a ManyToMany Relationship
- [Answer]-Reverse look up based on foreign key queryset data
- [Answer]-No such column: gallery_image.albums_id Django
- [Answer]-How can I seperate the objects in database and run the code by day?
Source:stackexchange.com