H
H
howuu2019-05-26 22:50:45
Django
howuu, 2019-05-26 22:50:45

Why is the form behaving strangely?

I don’t understand what’s wrong here, we have such a form

from django import forms
from .models import Customer

class CustomerForm(forms.ModelForm):
    class Meta:
        model = Customer
        fields = ('customer_name', )

it matches the model
class Customer(models.Model):
    customer_name = m
odels.CharField(max_length=64, blank=True, null=True, default=None)
    customer_phone = models.CharField(max_length=48, blank=True, null=True, default=None)
    customer_address = models.CharField(max_length=128, blank=True, null=True, default=None)
    session_key = models.CharField(max_length=128, blank=True, null=True, default=None)

views:
order = get_object_or_404(Order, session_key = request.session.session_key, status = status)
form = CustomerForm(request.POST)
if request.method == "POST":
    if form.is_valid():
        сustomer = form.save(commit=False)
        customer.session_key = order.session_key
        customer.save()

but at the moment when we submit the form and it is processed in views, the console issues
customer.session_key = order.session_key
NameError: name 'customer' is not defined

Why, because we have commit = False, I beat my head, I can’t understand

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
marazmiki, 2019-05-27
@howuu

I suspect you have a typo here. Most likely, instead of the English "C" Russian "C" is typed :) сustomer = form.save(commit=False)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question