formset issue

2008-08-26 Thread patrickk
scenario: users are uploading documents (e.g. images, files, ...). these documents are saved in a model "Attachment" assigned to the currently logged-in "User". now, every user has the possibility to attach documents to a blog-entry. these attachments are saved in a model "BlogEntryAttachment" ass

formset issue

2010-04-07 Thread Emanuel
Hi I have a formset and I'm passing initial data: DeletionFormset = formset_factory(deletionForm, extra=0) formset = DeletionFormset(initial=make_initial_data(instance)) The initial data arrives to the constructor fine. When the construct bilds the forms it overrides a ChoiceField with a

formset issue

2010-04-07 Thread Emanuel
I've send this post this morning: Hi I have a formset and I'm passing initial data: DeletionFormset = formset_factory(deletionForm, extra=0) formset = DeletionFormset(initial=make_initial_data(instance)) The initial data arrives to the constructor fine. When the construct bilds the forms

Re: formset issue

2008-08-27 Thread patrickk
anyone? On Aug 26, 12:19 pm, patrickk <[EMAIL PROTECTED]> wrote: > scenario: users are uploading documents (e.g. images, files, ...). > these documents are saved in a model "Attachment" assigned to the > currently logged-in "User". now, every user has the possibility to > attach documents to a bl

Re: formset issue

2008-08-31 Thread patrickk
sorry for being so annoying with this issue, but I´m asking this one more time. - with using inlineformset_factory, my problem is that limiting the choices to the currently logged-in user seems impossible. I´ve just tried to write a custom manger with "use_for_related_fields = True", but it´s als

Re: formset issue

2008-09-01 Thread patrickk
found a solution: with using threadlocals, it´s possible to define a custom manager which only returns the data assigned to the currently logged-in user. since threadlocals has been considered a "hack" recently by one of the main django-developers (I think it was malcolm), this is probably not the

Re: formset issue

2008-09-01 Thread koenb
I have not tried this, but can't you just in your view instantiate the formset and then loop over the forms and set the queryset on your field ? Koen On 1 sep, 09:24, patrickk <[EMAIL PROTECTED]> wrote: > found a solution: with using threadlocals, it´s possible to define a > custom manager which

Re: formset issue

2008-09-01 Thread patrickk
that seems to be possible. on the other hand, it also seems to be a strange way to go: instantiating the formset (retrieving all data/ querysets) and then changing the querysets? performance-wise, this is probably not a good solution. and I doubt that this is a good decision design-wise ... thank

Re: formset issue

2008-09-01 Thread koenb
Are you sure the data will be retrieved twice ? I thought those queryset definitions were lazy, so they are only executed when the widgets are rendered. Hmm, I'll try that out some time to check. Koen On 1 sep, 14:18, patrickk <[EMAIL PROTECTED]> wrote: > that seems to be possible. on the other

Re: formset issue

2008-09-02 Thread patrickk
hmm, if the data won´t be received twice this might be a solution. do you have any idea about the syntax? attachment_formset = BookingAttachmentFormSet(prefix="attachments") for form in attachment_formset: ??? how do I set initial_data here ??? thanks, patrick On Sep 1, 3:39 pm, koenb <[EMA

Re: formset issue

2008-09-02 Thread koenb
Something like this might work I think: attachment_formset = BookingAttachmentFormSet(prefix = "attachments") for form in attachment_formset.forms: form.fields['attachment'].queryset = Attachment.objects.filter(user=request.user) Koen On 2 sep, 13:05, patrickk <[EMAIL PROTECTED]> wrote: > h

FormView and django-formset Issue

2013-09-13 Thread vijay shanker
Hi i used formsets in generic FormView like this: class RequestRecommendationView(FormView): template_name = "account/stepfour.html" form_class = formset_factory(StepFourForm) def form_valid(self,form): print form.is_valid() cleaned_data = form.cleaned_data # r

FormSet issue. Pre-populating from queryset

2008-12-11 Thread maeck
The example below is a snippet from a view where I use a form to show 'Parent' and a formset to show its 'Children'. If I get the children as a queryset and pass it on to the formsets initial property, it errors out with: 'Parent' object is not iterable InlineFormSet = formset_factory(InlineFor

Re: FormSet issue. Pre-populating from queryset

2008-12-11 Thread Malcolm Tredinnick
On Thu, 2008-12-11 at 20:19 -0800, maeck wrote: > The example below is a snippet from a view where I use a form to show > 'Parent' and a formset to show its 'Children'. > If I get the children as a queryset and pass it on to the formsets > initial property, it errors out with: 'Parent' object is

Re: FormSet issue. Pre-populating from queryset

2008-12-11 Thread maeck
Thanks Malcolm, Just figured out the values transformation on querysets myself. Nevertheless, in my experience there seems to be an issue with foreignkeys when using queryset values in combination with formsets. Values returns keys like 'parent_id', however formsets expect the fieldname as 'paren

Re: FormSet issue. Pre-populating from queryset

2008-12-11 Thread Brian Rosner
On Thu, Dec 11, 2008 at 9:55 PM, maeck wrote: > Now I can pass the fieldnames as values('parent') for now, It would be > easier if initial did not care if the _id is provided or not. > Or am I missing something else? You shouldn't be using a regular formset. Django provides model formsets that k

Re: FormSet issue. Pre-populating from queryset

2008-12-11 Thread Malcolm Tredinnick
On Thu, 2008-12-11 at 20:55 -0800, maeck wrote: [...] > Now I can pass the fieldnames as values('parent') for now, It would be > easier if initial did not care if the _id is provided or not. > Or am I missing something else? What you're missing, or rather, assuming, is that querysets are ideal o

Re: FormSet issue. Pre-populating from queryset

2008-12-11 Thread maeck
Malcolm, Thanks for the comment. I truly understand where this is coming from. This issue is completely my issue of taking things for granted. I have been coding around in Django for a while now (hooked on in the 0.95 days), and have been coding most of the form stuff (including inlines) all by h