我所有的对象 newmedia 都以相同的名称保存。我怎样才能解决这个问题?
#view.py
if request.method == 'POST':
formset = MediaFormSet(request.POST, request.FILES)
if formset.is_valid():
Page_key = Page.objects.get(pk=1)
slide = SlideshowComponent(page=Page_key, order=0, label="slideshow", x=0, y=0, width=0, height=0, viewport_type="simle_page", keywords="slideshow")
slide.save()
for filename, file in request.FILES.iteritems():
name = request.FILES[filename].name
for form in formset.forms:
file_type = file.content_type
if file_type == "image/png" or file_type == "image/jpeg" or file_type == "image/gif":
newmedia = formset.save(commit=False)
newmedia.filename = name
newmedia.content_type = "photos"
newmedia.save()