I'm using Django version 0.96-pre I checked out from SVN on the 12th.
I have two models: Photo and SsiStatus (see code below)
A SsiStatus object can have many photos.
I have written a view to handle updating the SsiStatus and every time I
click to save the update the caption of any existing photos gets
duplicated. The file name is not, it remains blank.
If I add a new photo, the photo is added but any existing photos get
their captions duplicated.
I edited some other data on the page (not photos) and I took a look at
"new_data" before and after the line
"manipulator.do_html2python(new_data)" and got this:
BEFORE
'photo.0.caption': ['SSI Diagram for ssi: 14-1024'],
'photo.0.image': ['ssi\\13-14-1024____.jpg']
'photo.1.caption': [''],
'photo.1.image': [''],
AFTER
'photo.0.id': [None],
'photo.0.caption': ['SSI Diagram for ssi: 14-1024'],
'photo.0.image': ['ssi\\13-14-1024____.jpg']}>
'photo.0.image_file': [],
'photo.1.id': [None],
'photo.1.caption': [''],
'photo.1.image': [''],
'photo.1.image_file': [],
It didn't seem to change the data significantly.
The problem seems to occur when the ssi status object gets saved.
I made a small edit clicked "edit and continue" and after the
post-save-redirect the "debug" tag on the update page revealed this...
'photo.0.id': 19L,
'photo.0.caption': 'SSI Diagram for ssi: 14-1024',
'photo.0.image': 'ssi\\13-14-1024____.jpg'},
'photo.1.id': 88L,
'photo.1.caption': 'SSI Diagram for ssi: 14-1024', <---- DUPLICATED
NAME
'photo.1.image': '', <---- NO IMAGE
'photo.2.id': None, <---- Next blank image
'photo.2.caption': '',
'photo.2.image': '',
Has anyone seen this behaviour before?
Any help would be greatly appreciated.
---------------------------------------------------------------
View
---------------------------------------------------------------
def ssi_status_update(request, ssi_id, ssistatus_id):
# Get the ssi status in question from the database and create a
# ChangeManipulator at the same time.
try:
manipulator = SsiStatus.ChangeManipulator(ssistatus_id)
except SsiStatus.DoesNotExist:
raise Http404
if request.method == 'POST':
new_data = request.POST.copy()
if request.FILES:
print request.FILES
new_data.update(request.FILES)
errors = manipulator.get_validation_errors(new_data)
if not errors:
print new_data
manipulator.do_html2python(new_data)
print new_data
manipulator.save(new_data)
# Do a post-after-redirect so that reload works, etc.
if new_data.has_key('_continue'):
return
HttpResponseRedirect('/ssi/ssi_status/update/%s/%s/' %
(ssi_id, ssistatus_id))
else:
return HttpResponseRedirect('/ssi/%s/' % ssi_id)
else:
errors = {}
# This makes sure the form accurately represents the fields of
the document.
new_data = manipulator.flatten_data()
form = forms.FormWrapper(manipulator, new_data, errors)
return render_to_response('ssi/ssistatus_form.html',
{'form': form,
'object':SsiStatus.objects.get(pk=ssistatus_id)},
context_instance=RequestContext(request))
---------------------------------------------------------------
Models
---------------------------------------------------------------
class Photo(models.Model):
ssi_status = models.ForeignKey(SsiStatus, edit_inline=True,
num_in_admin=2)
caption = models.CharField(maxlength=100, core=True)
image = models.ImageField(upload_to="ssi")
def __str__(self):
return self.caption
def get_absolute_url(self):
from idms.settings import MEDIA_URL
return "%s/%s" % (MEDIA_URL, self.image.replace("\\","/"))
class SsiStatus(models.Model):
'''
This model is used to manage ssi status.
It can have many SSis
'''
title = models.CharField(maxlength=100, unique=True)
tail_number = models.ManyToManyField(Aircraft)
justification = models.TextField()
status = models.IntegerField(choices=SSI_STATUS_CHOICES)
priority = models.IntegerField(choices=PRIORITY_CHOICES)
---------------------------------------------------------------
template
---------------------------------------------------------------
<fieldset style="width:750px"><legend>Photos</legend>
<table cellpadding="3px">
{% for photo in form.photo %}
<tr>
<td><label for="id_.photo.{{ forloop.counter0
}}.caption">Caption:</label>
{{ photo.caption }}
</td>
<td><label for="id_photo.{{ forloop.counter0 }}.image_file">File
name:</label>
{{ photo.image_file }}
{{photo.image}}
</td>
</tr>
{% endfor %}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---