我一直在扩展以下项目:jquery 文件上传表单&我只想在名为 admin 的列中显示数据库中值为 1 的项目。
有人能告诉我如何修改以下基于类的视图以仅显示符合上述要求的图像吗?
class PictureCreateView(CreateView):
model = Picture
def form_valid(self, form):
self.object = form.save()
f = self.request.FILES.get('file')
data = [{'url': settings.MEDIA_URL + "pictures/" + f.name.replace(" ", "_"), 'thumbnail_url': settings.MEDIA_URL + "pictures/" + f.name.replace(" ", "_"), 'delete_url': reverse('upload-delete', args=[self.object.id]), 'delete_type': "DELETE"}]
response = JSONResponse(data, {}, response_mimetype(self.request))
response['Content-Disposition'] = 'inline; filename=files.json'
return response
def get_context_data(self, **kwargs):
context = super(PictureCreateView, self).get_context_data(**kwargs)
context['pictures'] = Picture.objects.all()
return context