Hi Malcom,
> I am not 100% certain what you are wanting to display in the repeating
> section of the form. Is it every photo in the system? Or maybe every
> photo associated with the existing "repair" instance? Sorry for being
> dense; I'm trying to work out the context from some code fragments
> without a description of what you would like to have happen and if I
> guess it will probably end badly.
I am trying to display all photos associated with a single repair and
allow the user to update the repair with an additional photo.
> It looks like you are trying to do the equivalent of
> repair.photo_set.all() in your template, but are using "form" instead of
> a "repair" object, which doesn't look promising. Since you mentioned
> later in this thread that you are trying to use the generic
> create.update.update_object() function,
You are right I was just taking a stab at something to get the desired
result. I understand now (I wished this clicked in earlier) that I am
really dealing with a dictionary.
>can you maybe post what your
> call this function looks like (either the URLConf line or the wrapper
> function that ends up calling update_object, depending upon how you've
> written your code).
I'm trying to rely on the generic view to do all the heavy lifting so
all the code there is to look at is the URLConf:
update_dict = {
'model':Repair,
'template_name':'tam/repair_update.html'
}
(r'^update/(?P<object_id>\d+)/$','django.views.generic.create_update.update_object',
update_dict),
NB: I have broken out create and update templates while I try to figure
out how to get the update working.
I have done some sleuthing and added <pre>{% debug %}</pre> at the top
of the template so I can see the contents of the Context.
I now see how the form wrapper works. All fields are are accessed by a
key value. So in the case of a repair form it is:
{'form': {'error_dict': {}, 'manipulator': , 'data': {'photo.0.id': 1,
'photo.0.caption': 'Oh my goodness!!!', 'repair_date': '1999-01-01',
'area': 13, 'tail_number': 102, 'photo.1.id': None, 'photo.1.filename':
None, 'damage_type': 'corrosion', 'photo.0.filename':
'tam\\damage1___.jpg', 'photo.1.caption': '', 'id': 1, 'location': 'L/H
lower sparcap WS 333'}, '_inline_collections': None, 'edit_inline':
True}
Notice that the photos come in as photo.<N>.<attribute>. In fact Django
supplies an extra "photo.1" that is blank. I am assuming this is due to
the "edit_inline" attribute.
***************
I guess the question really boils down to: How does one handle a form
wrapper if one doesn't know how many objects will be present?
***************
The following does NOT work but I hope it illustrates what I am trying
to accomplish...
{% for photo in form.keys %}
{% ifequal photo.startswith "photo"%}
<label for="id_{{ photo }}.caption">Photo Caption:</label>
{{ photo.caption }}
{% if photo.caption.errors %}
*** {{ photo.caption.errors|join:", " }}
{% endif %}
<label for="id_photo.{{ photo }}.filename_file">Photo
Filename:</label>
{{ photo.filename_file }}
{% if photo.filename_file.errors %}
*** {{ photo.filename_file.errors|join:", " }}
{% endif %}
{{ photo.filename }}
{% endifequal %}
{% endfor %}
The above in Python code would be something like:
for photo in form.keys():
if photo.startswith('photo'):
# ... do the output
This makes me think that I will have to abandon the generic view and
create the view myself. I'm not against it but then it begs the
question: What's the point of having generic views if all you can do is
deal with the most simple cases?
Once I have a solution to this I will be quite happy to contribute a
tutorial.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---