Test/app11/models.py
from django.db import models class Post(models.Model): title = models.CharField(max_length=200) content = models.TextField() pub_date = models.DateTimeField('date published') class Book(models.Model): title = models.CharField(max_length=100) author = models.CharField(max_length=100) publication_date = models.DateField() price = models.DecimalField(max_digits=5, decimal_places=2) def __str__(self): return self.title
Test/app11/views.py
from django.http import HttpResponse from app11.models import Book # 导入你的模型 def delete_book2(request): one_data = Book.objects.filter(author='小强1').delete() return HttpResponse("author=小强1的数据删除成功!")
Test/app11/urls.py
from django.urls import path from . import views urlpatterns = [ path('delete_book2/', views.delete_book2, name='delete_book2'), ]
http://127.0.0.1:8000/app11/delete_book2/
可以看到author为小强1的数据都被删除了