For ease of use, let's take the cancel out of the equation perhaps.
Url to create a new News Event:
### Create News Article
url(r'^account/news/add/$', login_required(CreateView.as_view(
model=NewsArticle,
form_class=NewsForm,
success_url=("/account/news"),
template_name="account/news_admin.html")),
name="admin-add-news"),
Url that gets called when I chose to insert an image into the WYSIWYG editor (and calls 'upload_photos' that has the NewsArticle.objects.create())
### Redactor.js WYSIWYG Editor
###
url(r"^uploads/$", "web_site.News.views.upload_photos", name="upload_photos"),
url(r"^recent/$", "web_site.News.views.recent_photos", name="recent_photos"),
and the views themselves:
@csrf_exempt
@require_POST
@login_required
def upload_photos(request):
images = []
for f in request.FILES.getlist("file"):
obj = NewsArticle.objects.create(upload=f, is_image=True)
images.append({"filelink": obj.upload.url})
return HttpResponse(json.dumps(images), mimetype="application/json")
@login_required
def recent_photos(request):
images = [
{"thumb": obj.upload.url, "image": obj.upload.url}
for obj in NewsArticle.objects.filter(is_image=True).order_by("-date_created")[:20]
]
return HttpResponse(json.dumps(images), mimetype="application/json")
I've tried to set a .save(commit=False) on obj -- that doesn't work.
I realize the behavior is call 'upload_photos' and it'll create the object in the database, but on any other event other than submission of the form, I want that object to no longer exist. I guess I want it to ONLY get created upon form submission.