社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  lucutzu33  »  全部回复
回复总数  2
3 年前
回复了 lucutzu33 创建的主题 » Django 3.0中未定义名称“render_to_response”

来自文档:

render_to_response(template_name, context=None, content_type=None, status=None, using=None)

Deprecated since version 2.0.

This function preceded the introduction of render() and works similarly except that it doesn’t make the request available in the response.

https://docs.djangoproject.com/en/2.2/topics/http/shortcuts/#render

3 年前
回复了 lucutzu33 创建的主题 » Django Tabular Inline没有外键问题

你把一对夫妻的关系搞错了。形象应该是产品的外键。这样,一个产品可以有多个图像。

class Image(models.Model):
    image = models.ImageField()
    imageMetaKeyWords = models.CharField("Meta keywords for SEO", max_length = 255,
    help_text = "Comma delimited words for SEO")
    imageMetaDescription = models.CharField("Meta description", max_length = 255,
    help_text = "Content for image meta tag description")
    defaultImage = models.BooleanField(default= False)
    product = models.ForeignKey("Product", on_delete=models.CASCADE, related_name="images") 
    #if you want to get the product's images you can call product.images

并删除以下内容:

productImages = models.ForeignKey(Image, on_delete=models.CASCADE)

迁移,然后在你的管理员。py:

from django.contrib import admin
from .models import Product, Image
from .forms import ProductAdminForm

# Register your models here.
class ImageTabularInline(admin.TabularInline):
    model = Image

class ProductAdmin(admin.ModelAdmin):
    form = ProductAdminForm
    inlines = [ImageTabularInline,]
    
    class Meta:
        model = Product

admin.site.register(Image)
admin.site.register(Product, ProductAdmin)