views:

8

answers:

1

First try at playing with model formsets with django and was wondering how to filter by the logged in user. The view below renders a form with all the profiles when I only want them to list one (the user's one).

def create_profile(request):
   ProfileFormSet = modelformset_factory(Profile)
   if request.method == 'POST':
       formset = ProfileFormSet(request.POST, request.FILES)
       if formset.is_valid():
           instances = formset.save()
    else:
        formset = ProfileFormSet()
return render_to_response('create_profile.html', {'formset': formset}, context_instance=RequestContext(request))
+1  A: 

If you only want one, why are you using formsets at all? You just need a standard modelform.

Daniel Roseman
And this is why I shouldn't try to code when hungover! Thanks.
Rob B