だから私のモデルでは。入力したフォームを空白にできるように、 blank=True があります。しかし、ユーザーがフォームを送信すると、空白のアイテムがデータベースに書き込まれます。これは、私が望んでいたことではありません。空白のフォームの処理方法を制御する他のオプションはありますか?
編集: 最後に、フォームに文字が含まれるすべてのフィールドをデータベースに追加し、文字が入力されていないすべてのフィールドを省略したいと思います。
models.py
class Cashtexts(models.Model):
cashcode = models.CharField(max_length=100, blank=True) #change me to a website filter
superPoints_Link = models.CharField(max_length=100, blank=True)#chance to "superPoints _Username"
varolo_username = models.CharField(max_length=100, blank=True)
swagbucks_username = models.CharField(max_length=100, blank=True)
neobux_username = models.CharField(max_length=100, blank=True)
topline_id = models.CharField(max_length=100, blank=True)
Paidviewpoint_id = models.CharField(max_length=100, blank=True)
cashcrate_id = models.CharField(max_length=100, blank=True)
で、景色はこちら
def submit_win(request):
if request.method == 'POST':
if Cashtexts.objects.filter(cashcode=request.POST['cashcode']).exists() or Cashtexts.objects.filter(superPoints_Link=request.POST['superPoints_Link']).exists() or Cashtexts.objects.filter(varolo_username= request.POST['varolo_username']).exists() or Cashtexts.objects.filter( swagbucks_username = request.POST['swagbucks_username']).exists() or Cashtexts.objects.filter(neobux_username = request.POST['neobux_username']).exists() or Cashtexts.objects.filter(superPoints_Link=request.POST['topline_id']).exists() or Cashtexts.objects.filter(superPoints_Link=request.POST['Paidviewpoint_id']).exists() or Cashtexts.objects.filter(superPoints_Link=request.POST['cashcrate_id']).exists() == False:
form = CashtextsForm(request.POST)
if form.is_valid():
c={}
c.update(csrf(request))
form.save()
return render_to_response('submitted_page.html',c)
else: #Error message reading wither you didnt insert codes or you enter the same code twice
error = 'you have already entered that code'
ref_create = CashtextsForm()
return render_to_response('submit.html', {'ref_create': ref_create,'error':error})
else: #displays the page when the user asks to go to the submit page
ref_create = CashtextsForm()
return render_to_response('submit.html', {'ref_create': ref_create}, RequestContext(request))