On Tue, Feb 10, 2009 at 5:37 PM, Skylar <skylar.savel...@gmail.com> wrote:
> > I get rendered > <label for="id_authorizedpickupperson_set-0-id">Id</label> also > <label for="id_authorizedpickupperson_set-0-user">User</label> > This is a rather huh?-inducing start to a bug report. Without context, those two <label> outputs look perfectly fine. It really helps if you start with what you are doing at a high level, the code you are using to attempt to achieve that, what you expected the result of running the code to be, and what you got instead. You started at the end of that and worked backwards, leaving out what you expected and what you are doing at a high level. > > ### The mostly relevent part of views.py: > > from django.forms.models import inlineformset_factory > @login_required > def pickup(request): > try: > profile = request.user.get_profile() > except: > return HttpResponseRedirect('/profile/') > > PickUpFormSet = inlineformset_factory(UserProfile, > AuthorizedPickUpPerson, max_num=5, fields=('name', 'relationship', > 'phone')) Ah, so maybe the issue is you did not specify the id and user fields in the form, therefore weren't expecting them to be rendered? If so, why couldn't you have mentioned that instead of asking people to trawl through a page of code trying to guess what it was you were trying to report? If not, I'm still lost as to what your issue is, because I stopped guessing at this point and am proceeding on the assumption that you don't expect those fields to be in the form since you did not explicitly list them. Without actually digging into the formset code, I have a feeling those fields (primary key and fk to parent model) are always included as hidden fields in the inline formset forms. They're needed for properly keeping track of things, so even if you don't explicitly list them, they will be there. They will be hidden, though, and you would see that by checking the output of as_p(), for instance, on one of these forms. So then the question is why are the labels appearing on your form? > > if request.method == "POST": > formset = PickUpFormSet(request.POST, instance=profile ) > if formset.is_valid(): > instances = formset.save(commit=False) > for instance in instances: > instance.user = profile() > instance.save() > return HttpResponseRedirect('/') > > else: > formset = PickUpFormSet(instance=profile, ) > > context = {'formset':formset, 'profile':profile,} > return render_to_response('pickup.html', context, > context_instance=RequestContext(request)) > > ###Rendering to this template: > > <form method="POST" action="/pickup/"> > {{ formset.management_form }} > > {% for form in formset.forms %} > {% for field in form %} > {{ field.label_tag }}: {{ field }} </br> > {% if field.help_text %} > {{ field.help_text }}{% endif %} > {% if field.errors %}{{ field.errors }}{% endif %} > {% endfor %} > {% endfor %} > > <input type="submit" value="Update"> > </form> > You have your own field-by-field rendering but do not check the is_hidden attribute for a field before rendering the field label. See its description at the end of the attribute list discussed here: http://docs.djangoproject.com/en/dev/topics/forms/#looping-over-the-form-s-fields See also the discussion of looping over hidden and visible fields here: http://docs.djangoproject.com/en/dev/topics/forms/#looping-over-hidden-and-visible-fields Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---