Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

async delete from DB using Django 4.2 with adelete()

As per docs since v4.2 Django comes with async version of delete method named adelete(). But I do not understand how to delete an object from DB using it.

db_object = await DbModel.objects.aget(pk=module_id)
await db_object.adelete() # doesn't work

It fails with an error:
"AttributeError: 'DbModel' object has no attribute 'adelete'

What is wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

adelete is a queryset method, not a method on the model.

So you can’t delete single object using adelete.

https://docs.djangoproject.com/en/4.2/ref/models/instances/#deleting-objects

try this

await DbModel.objects.filter(pk=module_id).adelete()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading