django-formsets

Django: How to iterate over formsets and access cleaned data?

What if I want to do something with my formset other than immediately saving it? How can I do this? for form in vehicles_formset.forms: listing.id = None listing.vehicle_year = form.cleaned_data['year'] listing.vehicle_make = form.cleaned_data['make'] listing.vehicle_model = form....

How do I create an empty Django formset using modelformset_factory?

I'm creating a formset, but it seems to populate it with all of the existing data in the table for that object. I can't figure out how to start with a blank formset; the only way seems to be to delete all of the data from the table, but clearly this isn't an option. I will post code if necessary (but there's lots of it, so knowing what ...

Django Inline formset for editing multiple related records at once - the right way to go?

Hi, When using inline formsets, how does one do paging? I'm using django 1.1. The situation I'm in, is that the user needs to be able to edit the related objects quickly and easily (which is why I think I should be using an inline formset). However, there can be a more than a hundred objects to edit, which makes a pretty large formset,...

How do I flag only one of the formsets in django admin?

I have these (simplified) models: class Question(models.Model): question = models.CharField(max_length=60) class Choices(models.Model): question = models.ForeignKey(Question) text = models.CharField(max_length=60) is_correct = models.BooleanField(default=False) I've made Choices as an inline of Question (in admin). ...

Filter Queryset in Django inlineformset_factory

I am trying to use inlineformset_factory to generate a formset. My models are defined as: class Measurement(models.Model): subject = models.ForeignKey(Subject) experiment = models.ForeignKey(Experiment) assay = models.ForeignKey(Assay) values = models.CommaSeparatedIntegerField(blank=True, null=True) class Experiment(m...

Three questions before I leave PHP: Formsets, datasources and remote auth

I've been using CakePHP for a long time now and feel comfortable developing sites with it. I do however like Python more then PHP and would like to move to Django. EDIT: split in three separate questions How can I mix multiple models in one form? I know formsets are used for this, but I can't find a decent tutorial on this (views + tem...

How to manually render a Django template for an inlineformset_factory with can_delete = True / False

I have an inlineformset with a custom Modelform. So it looks something like this: MyInlineFormSet = inlineformset_factory(MyMainModel, MyInlineModel, form=MyCustomInlineModelForm) I am rendering this inlineformset manually in a template so that I have more control over widgets and javascript. So I go in a loop like {% for form in myfo...

Django formsets problem.

Hi, I am trying to produce a template with many addresses (forms), where you can add, edit and remove them. Am I doing something wrong with formsets? Here are my views: @login_required def addresses(request): AddressesFormset = modelformset_factory(Address, can_delete = True, ...

Create Django formset wihtout multiple queries

I need to display multiple forms (up to 10) of a model on a page. This is the code I use for to accomplish this. TheFormSet = formset_factory(SomeForm, extra=10) ... formset = TheFormSet(prefix='party') return render_to_response('template.html', { 'formset' : formset, }) The problem is, that it seems to me that Django queries...

Django: How can I delete a formset entry if one of it's data is blank?

Hi, I have the following scenario: I have a form with data that does not need translation and a formset with a textfield that should be translated into an undefined amount of languages. Both parts are bound to a model. Each translated text is kept in a model with a foreign key that binds it to the untranslatable data. Something like: ...

Django, how to create form for add/edit object with m2m links?

Good afternoon! There are three essences. Product, Option and ProductOption. Product has link many to many to Option through ProductOption. Prompt how to create please for Product'a the form of addition/editing with these options (not on administration page)? If simply to output {{product.options}} - will be SelectBox with a plural choi...

Formset Messages

I want to be able to send a message using the new messages framework. Something along the lines of : ... if formset.is_valid return HttpResponseRedirect( some page ) messages.add_message(request,messages.INFO, '%i objects added') %formset.number_of_forms But two questions: Im not sure if i should put the messages bef...

Django nested formsets

Hi, I have an edit object view that contains a formset(one or many if this matters), now I want to create a page that can display multiple edit object forms and submit it in a single form. What is the correct way to achieve this task? ...

Display additional data while iterating over a Django formset

Hi, I have a list of soccer matches for which I'd like to display forms. The list comes from a remote source. matches = ["A vs. B", "C vs. D", "E vs, F"] matchFormset = formset_factory(MatchForm,extra=len(matches)) formset = MatchFormset() On the template side, I would like to display the formset with the according title (i.e. "A vs...

Building a formset dynamically

I initially wrote code to build a form dynamically, based on data from the DB, similar to what I described in my previous SO post. As SO user Daniel Roseman points out, he would use a formset for this, and now I've come to the realization that he must be completely right. :) My approach works, basically, but I can't seem to get valida...

How to render a text box instead of a select box when using model form set

Hi, When I render my formset, one of the field renders as a select box because it is a foreign field in the model. Is there a way to change this to a text input? I want to populate that field by using Ajax auto complete. Adding a widget to the modelform is not working because the modelformset_factory takes a model and not a model form. ...

Django inline formset with child of a child

Heya! I have three models: Variable, which has Group as a foreign key Group, which has Set as a foreign key Set I want to create a form that lets user create a new Set based on existing Set. Only things that user is able to modify are the Set name and Variable values. This has given me an idea of using inlineformset_factory to acce...

Setting a foreign key on a formset on formset.save()

Hi all, It's simple - All I want to do is set who answered the question if the question is answered. Can someone please enlighten me on how to set a form value if the question was answered. I know that I could also set this as an initial value but then I have to selectively determine which records were answered. This seemed simpler bu...

empty_form initial value for a modelformset_factory

I try to add initial values to the empty form of a modelformset_factory. FormSet = modelformset_factory(MyModel, extra=2) formset = FormSet(queryset=MyModel.objects.none(), initial=[{'foo': 'bar'}, {'foo': 'bar'}]) I would like to set initial value to the formset.empty_form , how can I achieve this ? ...

paginate and sort a formset?

I'm trying to use directeur's Django-sorting in a modelformset. My template code looks like this: {% load sorting_tags %} <table style="text-align: left;" border="1" cellpadding="5" cellspacing="0"> {% autosort formset.forms %} {% for form in formset.forms %} {% if forloop.first %} <tr> {% for field in form %} ...