2
from django.contrib.auth.models import User
class Drink(models.Model):
owner = models.ForeignKey(User)
name = models.CharField(max_length=50)
如何刪除用戶註銷後的所有飲料?如何在用戶註銷後刪除對象?
def delete_drink(request):
user = request.user
drink = Drink.objects.filter(owner=user)
drink.delete()
A信號coould滿足您的需求。 http://stackoverflow.com/questions/1990502/django-signal-when-user-logs-in – Jingo