Django管理站点未选择当前图像URL [英] Django admin site does not pick current image URL

查看:121
本文介绍了Django管理站点未选择当前图像URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Django管理站点中编辑我的一个对象的字段,我的模型中也有一个Cloudinary图像字段.问题是,每当我尝试对对象的 CharField 之一进行编辑时,都会收到错误消息:

I am trying to edit the fields of one of my objects in the Django admin site, I also have a Cloudinary image field in my model. The issue is, anytime I try to make an edit to one of the CharFields of my object, I get the error:

value too long for type character varying(100)

后来我发现,每次我完成编辑并尝试保存时,它都会寻找一个新图像来替换 imagefile 的当前图像,即使我没有触摸 imagefile ,因此它返回一个空的图像URL字符串,如下所示:

which I later found out that every time I finish my edits and I am trying to save, it looks for a new image to replace the current image of my imagefile even though I did not touch my imagefile, thus it returns an empty image URL string like this:

但是当前图像URL可以正常工作,并在单击时显示,如下所示:

But the current image URLworks fine and displays when clicked like this:

我只想知道我做错了什么,为什么每次单击保存时它都会寻找一个新的图像URL?

I just want to know if I am doing something wrong, why does it look for a new image URL every time I click save?

这是我的 models.py 文件:

from django.db import models
from cloudinary.models import CloudinaryField

class profiles(models.Model):
    firstname = models.CharField(max_length=120, default = 'null') #max_length=120
    lastname = models.CharField(max_length=120, default = 'null') 
    gender = models.CharField(max_length=120, default = 'null') 
    dob = models.CharField(max_length=120, default = 'null') 
    callNumber = models.CharField(max_length=120, default = 'null') 
    whatsappNumber = models.CharField(max_length=120, default = 'null') 
    ministry = models.CharField(max_length=120, default = 'null') 
    centre = models.CharField(max_length=120, default = 'null') 
    campus = models.CharField(max_length=120, default = 'null') 
    hostel_address = models.CharField(max_length=120, default = 'null') 
    city = models.CharField(max_length=120, default = 'null') 
    qualification = models.CharField(max_length=120, default = 'null') 
    profession = models.CharField(max_length=120, default = 'null') 
    maritalStatus = models.CharField(max_length=120, default = 'null') 
    bacenta = models.CharField(max_length=120, default = 'null') 
    layschool = models.CharField(max_length=120, default = 'null') 
    imagefile = CloudinaryField('image', max_length=512, null=False,  default = 
 'https://res.cloudinary.com/firslovetema/image/upload/v1566807474/h1psyutzptxlnhuk8uyr.png')



def __str__(self):
    return str(self.imagefile)

这是我先前的问题的后续问题,可以在这里找到

This is a follow up question to my previous question which can be found here:

值对于类型字符变化(100)而言太长了

推荐答案

Django在保存对象时会保存所有属性,而不仅仅是保存您已更改的属性.

Django saves all attributes, not just the ones you've changed, when you save an object.

Cloudinary库硬编码 max_length 到255 ,所以

The Cloudinary library hard-codes max_length to 255, so

  • 您的 max_length = 512 不执行任何操作,并且
  • 您应该不会在该字段上看到有关 VARCHAR(100)的错误.
  • your max_length=512 doesn't do anything, and
  • you shouldn't be seeing an error about VARCHAR(100) on that field.

您确定所有迁移都已在Heroku上应用吗?尝试运行

Are you sure that all of your migrations have been applied on Heroku? Try running

heroku run python manage.py migrate

这篇关于Django管理站点未选择当前图像URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆