我的表单'永远不会完全实例化,特别是ImageFields(就像他们在管理员中的样子)和TextFields(显示为标签)
但是,所有其他字段都已正确实例化。
我可以知道为什么会这样吗?
复制此问题的附加代码:
#view
sellerForm = SellerUpgradeForm(instance=userseller_prof)
#form
class SellerUpgradeForm(ModelForm):
def __init__(self,*args, **kwargs):
super(SellerUpgradeForm, self).__init__(*args, **kwargs)
self.fields['selling_currency'].queryset = Countries.objects.filter(paypal_valid="yes")
class Meta:
model = UserSeller
fields = ("seller_store_image","shop_description","selling_currency","auth_username",
"auth_password","auth_signature")
#model
class UserSeller(models.Model):
user = models.ForeignKey(User, verbose_name="User")
access_plan = models.ForeignKey(AccessPlan, verbose_name="Seller's Access Plan")
status = models.CharField(max_length=100, choices=SELLER_STATUS, verbose_name="Seller Status", default="unapproved")
rating = models.DecimalField(verbose_name="Rating (Upon 5)", decimal_places=2, max_digits=4, default=0)
total_rating_count = models.IntegerField(verbose_name="Rating Count", default=0)
selling_currency = models.ForeignKey(Countries, verbose_name="Currency that seller's product will be sold in")
meta = models.ManyToManyField(UserMeta, verbose_name="User Meta Data", blank=True, related_name="seller_meta")
shop_description = models.TextField(verbose_name="Description about the products you are selling")
seller_store_image = models.ImageField(upload_to=settings.CUSTOM_UPLOAD_DIR, verbose_name="Store Avatar", blank=True)
internal_note = models.TextField(verbose_name="Seller Note (Internal Use Only)", blank=True)
timestamp = models.DateTimeField(verbose_name="Date Created", auto_now_add=True)
auth_username = models.CharField(max_length=50, verbose_name="Paypal Auth Username")
auth_password = models.CharField(max_length=50, verbose_name="Paypal Auth Password")
auth_signature = models.CharField(max_length=100, verbose_name="Paypal Auth Signature")
class Meta:
verbose_name = "Seller Profile"
verbose_name_plural = "Seller Profiles"
app_label = "management"
def __unicode__(self):
return "Rating: " + str(self.rating)
答案 0 :(得分:2)
未预先填充ImageFields的原因是浏览器安全问题,与Django无关。
如果浏览器允许网页预填充文件输入,则网站很容易在未经用户同意的情况下从用户的硬盘驱动器上任意上传内容。因此,为了阻止这种情况发生,文件输入字段始终呈现为空白。
答案 1 :(得分:0)
糟糕。我有一个JS脚本,可以自动清除document.ready上的textareas,因此如下。忘记了这一点。
我的坏。