1π
β
This looks to me like a very basic Django question and I would recommend you learn how it works.
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)
# Change the all to some filter
context['pictures'] = Picture.objects.filter(admin=1)
return context
π€Wolph
Source:stackexchange.com