如何将django formset中的选项限制为最多5个。 我的观点是:
file_attachment_formset = get_audioattachment_formset(FileAttachmentForm, extra=1, can_delete=True)
我的表格为:
^{pr2}$在模型.py公司名称:
class FileAttachment(models.Model):
post = models.ForeignKey(Post, related_name = 'file_attachments')
picture = models.ImageField(upload_to = 'uploads/picture/', null = True, blank = True)
audio_video = models.URLField(null = True, blank = True, verbose_name = "Audio/Video URL", verify_exists = True)
在视图.py公司名称:
file_attachment_formset = get_audioattachment_formset(FileAttachmentForm, extra=1, can_delete=True, max_num=3)
if request.method == 'POST':
postForm = MyPostForm(request.POST, instance = post)
formset = file_attachment_formset(request.POST, request.FILES, instance = post)
if formset.is_valid():
#FileAttachment.objects.filter(post = newpost).delete()
formset = file_attachment_formset(request.POST, request.FILES, instance = newpost)
formset.save()
else:
formset = file_attachment_formset(instance = post)
帮助我如何将图片的选择限制在最多5个?在
使用formset函数传递
max_num
{kwarg>通常取这个集。试试看!在
相关问题 更多 >
编程相关推荐