Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Message from discussion #12213: Initial data and addition queryset_filter for formset from inlineformset_factory
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Django  
View profile  
 More options Jan 10 2010, 12:49 pm
From: "Django" <nore...@djangoproject.com>
Date: Sun, 10 Jan 2010 17:49:51 -0000
Local: Sun, Jan 10 2010 12:49 pm
Subject: Re: [Django] #12213: Initial data and addition queryset_filter for formset from inlineformset_factory
#12213: Initial data and addition queryset_filter for formset from
inlineformset_factory
---------------------------------+----------------------------------------- -
          Reporter:  ramusus     |         Owner:  nobody
            Status:  new         |     Milestone:        
         Component:  Forms       |       Version:  1.1  
        Resolution:              |      Keywords:        
             Stage:  Unreviewed  |     Has_patch:  1    
        Needs_docs:  0           |   Needs_tests:  1    
Needs_better_patch:  0           |  
---------------------------------+----------------------------------------- -
Changes (by lorochka85):

  * component:  Uncategorized => Forms

Comment:

 Queryset support was added to !BaseInlineFormSet (not initial though) in
 the development version and, imho, is better than dealing with filters.
 For initial, adding it as an extra argument to !BaseInlineFormset and then
 passing to the super's {{{ __init__ }}} does the job.

 However, it gets a little bit confusing when one tries to pass both
 initial and queryset to ether !BaseInlineFormSet or !BaseModelFormSet. For
 example, you have something like:

 {{{
 formset = BaseModelFormSet(...,
                            queryset=some_qs,
                            initial=[{'field1': 'f1value1', 'field2':
 'f2value1'},
                                     {'field1': 'f1value2', 'field2':
 'f2value2'}],
                           )
 }}}
 then values for field1 and field2 for the first 2 items in some_qs will
 get overriden with values in initial. In order for the formset to display
 first data from the queryset and then extra forms with values from
 initial, your initial should look something like:
 {{{
 initial = [{} for i in range(0, some_qs.count())] +
           [{'field1': 'f1value1', 'field2': 'f2value1'},
            {'field1': 'f1value2', 'field2': 'f2value2'}]
 }}}

 ...Having said all that, there is a nice little comment about instance and
 initial in {{{ BaseModelForm.__init__ }}}:
 [http://code.djangoproject.com/browser/django/trunk/django/forms/model...]
 {{{
 # if initial was provided, it should override the values from instance
 }}}
 I suppose this is valid for formsets as well. Should that be documented
 somewhere?

 Now, in terms of use cases for initial on InlineFormSet, there is one by
 Nathan in this thread: [http://groups.google.ru/group/django-
 developers/browse_thread/thread/73af9e58bd7626a8/e307d4865759a26e]

--
Ticket URL: <http://code.djangoproject.com/ticket/12213#comment:3>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.