I have added a feature to my Django app which allows me to import data
from an external database. The data is in XML. I iterate over the XML
to import book descriptions. After each book is processed, I save()
it. Then I call render_response() to display the list of books just
imported.
However, the list has holes, i.e. not all fields are displayed. If I
refresh the page, all book fields are now displayed. So they were
there previously and some background process has now completed.
# view
def import_xml(request):
if request.method == 'POST':
post_data = request.POST.copy()
post_data.update(request.FILES)
form = forms.XmlUploadForm(post_data)
if form.is_valid():
list, log = form.save()
return render_to_response('book_list.html', {'log': log,
'list': list})
form = forms.XmlUploadForm()
return home_page(request, form)
# form.save()
def save(self):
xmldata = self.clean_data['xml_file']['content']
xml = ElementTree.fromstring(xmldata)
return do_import_xml(xml)
The issue goes away if I rebuild the book list manually before calling
render_response():
# revised view
def import_xml(request):
if request.method == 'POST':
post_data = request.POST.copy()
post_data.update(request.FILES)
form = forms.XmlUploadForm(post_data)
if form.is_valid():
list, log = form.save()
# NEW
list = Book.objects.filter(pk__in=[b.id for b in list])
# END NEW
return render_to_response('book_list.html', {'log': log,
'list': list})
form = forms.XmlUploadForm()
return home_page(request, form)
Why the different behaviour? Am I doing anything wrong? Is there a
cache concurrency issue?
I use Django v0.96 and sqlite3.
Both the development server and Apache+mod_py exhibit the same
behaviour.
I have tried using @commit_manually and @never_cache, without success.
JJ.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---