我可以用Django創建一個具有mysql背景的表單。我想知道是否有可能創建一個允許您刪除對象的代碼。假設我有一個名爲「Tony」的客戶端,我想創建一些允許我刪除Tony的Python代碼。我會怎麼做?如何刪除一個入口對象對象
#forms.py
from django import forms
from c2duo.accounts.models import *
class ClientForm(forms.ModelForm):
client_number = forms.IntegerField()
name = forms.CharField(max_length=80)
address = forms.CharField(max_length=250)
telephone = forms.CharField(max_length=20)
fax = forms.CharField(max_length=20)
email = forms.EmailField()
alternative_name = forms.CharField(max_length=80, required=False)
alternative_address = forms.CharField(max_length=250, required=False)
alternative_telephone = forms.CharField(max_length=20, required=False)
alternative_email = forms.EmailField(required=False)
class Meta:
model = Client
fields = ('client_number','name','address','telephone','fax','email','alternative_name','alternative_address','alternative_telephone','alternative_email'
#views.py
@login_required
def add_client(request):
if request.method == 'POST':
form = ClientForm(request.POST or None)
if form.is_valid():
form.save()
return HttpResponseRedirect('/index/')
else:
form = ClientForm()
return render_to_response('add_client.html', {'form': form}, context_instance=RequestContext(request))
寫一個刪除來看。 – 2010-12-17 13:58:23