How Can I delete a record in Django models

0 votes

I want to delete a particular record. Such as

delete from table_name where id = 1;

How can I do this in a django model?

Jun 23, 2020 in Python by kartik
• 37,520 points
1,677 views

1 answer to this question.

0 votes

Hello @kartik,

If you want to delete one item

wishlist = Wishlist.objects.get(id = 20)
wishlist.delete()

If you want to delete all items in Wishlist for example

Wishlist.objects.all().delete()

Hope it is helpful!

Thank You!

answered Jun 23, 2020 by Niroj
• 82,840 points

Related Questions In Python

+1 vote
1 answer

How can I delete a file in Python IDLE?

Hey @Starsarwar You have two different codes, they ...READ MORE

answered Oct 28, 2019 in Python by Kalgi
• 52,350 points
2,481 views
+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,890 points
20,051 views
+2 votes
2 answers

How can I create a new file in Python?

You can try the below code which ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
1,322 views
+2 votes
4 answers

How can I replace values with 'none' in a dataframe using pandas

Actually in later versions of pandas this ...READ MORE

answered Aug 13, 2018 in Python by bug_seeker
• 15,510 points
122,410 views
0 votes
3 answers

Python Selenium best tutorials for beginners

Hope this will help you...Python Tutorial READ MORE

answered Feb 11, 2019 in Python by aldrinjohn
• 140 points
3,960 views
0 votes
1 answer

How can I have Multiple Models in a single django ModelForm?

Hello @kartik, You can just show both forms ...READ MORE

answered Aug 13, 2020 in Python by Niroj
• 82,840 points
11,918 views
0 votes
1 answer

How can I get the domain name of my site within a Django template?

Hello kartik, The variation of the context processor ...READ MORE

answered Apr 23, 2020 in Python by Niroj
• 82,840 points
9,844 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP