0

だから私のモデルでは。入力したフォームを空白にできるように、 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))
4

1 に答える 1

0

文字を含むすべてのフィールドにフォームを入力し、空の文字列の入力を省略したいのですが、複数の送信ボタンでこれを実行できることに気付きましたが、2 つまたは 3 つ以上のフィールドでは面倒です。

空の文字列が必要ない場合は、空のフィールドに None が必要であると想定できます。まず、それを可能にするモデル (およびデータベース) が必要です。そうしないと、機能しません。

私は次のように動作すると信じています: (ただし、なぜこれが本当に必要なのかはわかりません)

class Cashtexts(models.Model):
    cashcode = models.CharField(max_length=100, null=True, blank=True, default=None)
于 2012-04-05T22:32:35.800 に答える