H
H
hheellpp2018-07-28 14:05:29
Django
hheellpp, 2018-07-28 14:05:29

I don't understand what is wrong. 'Query' object has no attribute 'contains_column_references' so what's the problem?

this is in view:

def ShopProduct(request,name):
             Pro=Product.objects.filter(is_active=True ,id=name)
             form =BaseModelForm(request.POST or None)
             if form.is_valid():
                      new_form=form.save(commit=False)
                      kek=Product.objects.filter(id=name)
                      new_form.product_name=kek
                      new_form.save()# тут показывает ошибку
                      return render(request, "Green_way/body.html", locals())

             return render(request, "Green_way/page2.html", locals())

Forms:
from django.forms import ModelForm
from .models import Order


class BaseModelForm(ModelForm):
    class Meta:
        model=Order
        exclude = ["status","product","product_name"]

Models:
from django.db import models
from shop.models import Product

#from django.contrib.auth.models import User


class Status(models.Model):
    name = models.CharField(max_length=24, blank=True, null=True, default=None)
    is_active = models.BooleanField(default=True)
    created = models.DateTimeField(auto_now_add=True, auto_now=False)
    updated = models.DateTimeField(auto_now_add=False, auto_now=True)

    def __str__(self):
        return "Статус %s" % self.name

    class Meta:
        verbose_name = 'Статус заказа'
        verbose_name_plural = 'Статусы заказа'


class Order(models.Model):
    customer_name = models.CharField('ИМЯ И ФАМИЛИЯ',max_length=64, blank=False, null=True, default=None)
    customer_email = models.EmailField('ЭЛЕКТРОННАЯ ПОЧТА',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)
    customer_index = models.CharField('ИНДЕКС',max_length=50, blank=True, null=True, default=None)
    product_name =models.CharField('ИМЯ ПРОДУКТА',max_length=64, blank=True, null=True, default=None)
    status = models.ForeignKey(Status,blank=True, null=True, default=None,on_delete=models.SET_NULL)
    product = models.ForeignKey(Product,blank=True, null=True, default=None,on_delete=models.SET_NULL)

    def __str__(self):
        return "Заказ %s %s" % (self.id, self.customer_name)

    class Meta:
        verbose_name = 'Заказ'
        verbose_name_plural = 'Заказы'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question