Django.fun

Field 'id' expected a number but got '9dzlzyftu9k5fi5ta8omk1mxgx1lyvhg'

It works fine until the form is created, but if i enter a value and click the Submit button, the following error code is displayed. The long string of the error code is cart_id. How can I change it? This is a simulated payment system that receives a cart with products and makes a payment.

Error MSG

models.py

class Cart(models.Model):
    cart_id = models.CharField(max_length=250, blank=True)
    customer = models.ForeignKey(User, on_delete=models.CASCADE)
    date_added = models.DateField(auto_now_add=True)
    class Meta:
        db_table = 'Cart'
        ordering=['date_added']

    def __str__(self):
        return self.cart_id

class Payment(models.Model):
    cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
    card_number = models.IntegerField()
    validity = models.IntegerField()
    cvc = models.IntegerField()
    card_password = models.IntegerField()

    def __str__(self):
        return '{0} {1}'.format(self.cart, self.card_number)

urls.py

urlpatterns = [
    path('add/<int:pk>/', views.add_cart, name='add_cart'),
    path('', views.cart_detail, name='cart_detail'),
    path('remove/<int:pk>/', views.cart_remove, name='cart_remove'),
    path('full_remove/<int:pk>/', views.full_remove, name='full_remove'),
    path('payment_charge/', views.payment_charge, name='payment_charge'),
]

view.py

def _cart_id(request):
    cart = request.session.session_key
    if not cart:
        cart = request.session.create()
    return cart

def payment_charge(request):
    if request.method == "POST":
        form = PaymentForm(request.POST, request.FILES)
        if form.is_valid():
            post = form.save(commit=False)
            post.cart_id = _cart_id(request)
            post.save()
            return redirect('cart:cart_detail')
    else:
        form = PaymentForm()
    context = {
        'form' : form
    }
    return render(request, 'cart/payment_form.html', context)

forms.py

class PaymentForm(forms.ModelForm):
    class Meta:
        model = Payment
        fields = ('card_number','validity','cvc','card_password')

base.html

<div class="mx-auto">
    <a href="{% url 'cart:payment_charge' %}" type="button"
        class="btn btn-outline-dark my_custom_button">
            Continue Shopping
    </a>
</div>

payment_form.html

<form action="" method="POST">
    {% csrf_token %}
    <table>
        {{form.as_table}}
    </table>
    <input type="submit" value="제출">
</form>

Answers: 0