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....
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 ...
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,...
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). ...
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...
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...
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...
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,
...
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...
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:
...
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...
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...
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?
...
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...
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...
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.
...
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...
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...
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 ?
...
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 %}
...