我有这个表格:
class TourForm(ModelForm):
class Meta:
model = Tour
我想设计一个编辑页面,所以我把tour\u id发送到页面,然后用这个tour\u id得到tour,现在我想用我得到的tour实例填充这个表单哥顿。一些像这样的事情视图.py地址:
tour=Tour.objects.get(pk=tour_id)
tform = TourForm(request.POST, request.FILES,instance=tour)
有什么帮助吗?你知道吗
更新:
这些是模型:
class Gallery(models.Model):
HeadImage = models.ImageField(upload_to="gallery")
class Image(models.Model):
Image = models.ImageField(upload_to="gallery")
Gallery = models.ForeignKey(Gallery, related_name='images')
class Tour(models.Model):
Name=models.CharField(max_length=100)
Count=models.SmallIntegerField()
PriceUnit=models.ForeignKey(PriceUnit)
Price=models.CharField(max_length=12)
Description=models.TextField()
ActionDate=models.DateTimeField(auto_now=True,editable=False)
ActionUser=models.ForeignKey(User,editable=False)
StatusType=models.ForeignKey(StatusType)
Gallery = models.OneToOneField(Gallery,editable=False)
PriceUnit和StatusType等foreigkey字段不会填充表单。你知道吗
提前谢谢
我认为你不应该通过考试请求.POSt同时。试着这样做:
相关问题 更多 >
编程相关推荐