저는 장고에서 완전히 새로 왔으며 처음으로 장고 양식을 사용하려고합니다. 나는 이걸 찾았지만 대답을 정확히 찾지 못했습니다. 기본적으로이 같은 전망이 있습니다django 양식에 새 필드 추가
def pay(request):
if request.method == 'POST':
form = PaymentForm(request.POST)
if form.is_valid():
# I have to calculate the checksum here
myModel = form.save()
else:
print form.errors
else: # The request is GET
form = PaymentForm()
return render_to_response('payment/payment.html', {'form':form})
을하고 난 사용자가 검사를 추가하고 추가해야 할 항목을 제출 그래서 양식에서받은 입력에서 폼에 추가 필드, 검사를 추가하려면 양식 및 양식을 외부 서버로 보내야합니다. 그러나 나는 그것을 수행하는 방법을 모른다 (나는 모델에 체크섬을 정의했다). 아무도 이걸 도와 줄 수 없습니까?
class PaymentModel(models.Model):
alphanumeric = RegexValidator(r'^[0-9a-zA-Z]*$', 'Only alphanumeric characters are allowed!')
secret_key = '6cd118b1432bf22942d93d784cd17084'
pid = models.CharField(primary_key=True, max_length=50, validators=[alphanumeric])
sid = models.CharField(primary_key=True, max_length=50, validators=[alphanumeric])
amount = models.DecimalField(max_digits=9, decimal_places=2)
success_url = 'http://localhost:8000/success'
cancel_url = 'http://localhost:8000/cancel'
error_url = 'http://localhost:8000/error'
checksum = 0
def calc_checksum(self):
checksumstr = "pid=%s&sid=%s&amount=%s&token=%s"% (self.pid, self.sid, self.amount, self.secret_key)
m = md5(checksumstr)
checksum = m.hexdigest()
return checksum
def __unicode__(self): #returns the unicode representation of the object
return self.name
및 내 양식은 다음과 같습니다 :
내 모델은 다음과 같습니다
class PaymentForm(ModelForm):
class Meta:
model = PaymentModel
이 필드를'PaymentForm'에 추가해야합니다 ... – Silwest
질문을 업데이트하고 주석을 보내지 않고 양식 구조를 추가 할 수 있습니다. 'ModelForm'을 사용하기 때문에'PaymentModel'을 게시하는 것이 더 좋습니다. – FallenAngel
제안한대로 스레드를 편집했습니다. –