Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
deddy edoward
17,412 PointsDelete () vs Delete_instance() ?
Hi Everyone, I little bit confusing about delete() and delete_instance() in PeeWee. can you give me explain about that?
1 Answer
Myers Carpenter
6,421 Pointsdelete() starts a delete sql statement. You can add .where() to narrow down what you are deleting. It's a class method.
class User(Model):
username = CharField()
join_date = DateTimeField(default=datetime.datetime.now)
is_admin = BooleanField()
User.delete() # would delete all users in the database
delete_instance() is a instance method, that will delete the database row represented by an instance of a Model subclass.
me = User.create(username="myers") # create a new user with my username
me.delete_instance() # delete me from the database