formset

How to add custom fields to InlineFormsets?

I'm trying to add custom fields to an InlineFormset using the following code, but the fields won't show up in the Django Admin. Is the InlineFormset too locked down to allow this? My print "ding" test fires as expected, I can print out the form.fields and see them all there, but the actual fields are never rendered in the admin. admin...

Setting values to the output of a formset in Django

This question is somewhat linked to a question I asked previously: http://stackoverflow.com/questions/477183/generating-and-submitting-a-dynamic-number-of-objects-in-a-form-with-django I'm wondering, if I've got separate default values for each form within a formset, am I able to pre-populate the fields? For instance, a form requiring ...

Django Forms - How to access data when form.is_valid() is false

When I have a valid Django form, I can access the data with form.cleaned_data. But how do I get at the data a user entered when the form is not valid i.e., form.is_valid is false. I'm trying to access forms within a form set, so form.data seems to just give me a mess. ...

Model Formset Issue.

I have a model for which the need is to show the form multiple times. I have used it under a modelformset. I seem to have a problem with the id of this model which is also the primary key for the model. I prepopulate the formset with data which I wish to edit. But whenever I click on submit it refreshes the page back with an error saying...

How to show hidden autofield in django formset

Hi everyone, A Django autofield when displayed using a formset is hidden by default. What would be the best way to show it? At the moment, the model is declared as, class MyModel: locid = models.AutoField(primary_key=True) ... When this is rendered using Django formsets, class MyModelForm(ModelForm): class Meta: model ...

Creating modelformset from a modelform

Hi everyone, I have a model MyModel which contains a PK - locid, that is an AutoField. I want to construct a model formset from this, with some caveats: The queryset for the formset should be a custom one (say, order_by('field')) rather than all() Since locid for MyModel is an AutoField and thus hidden by default, I want to be able t...

Django Formset.is_valid() failing for extra forms

In my Django application application I have a formset that is created from a simple (not-model) form, with the extra=1 (to allow javasript to add more forms later on). class SomeForm(forms.Form): #some fields with required=False length = forms.IntegerField(required=False) # An example of one of the fields with choices i hav...

Changing field type in a Django ModelFormset

In a Django ModelForm, you can change the widget type of a field like so: class EntryForm(ModelForm): entity = forms.CharField() class Meta: model = Entry I can easily create a modelformset from the same model like so: EntryFormSet = modelformset_factory(Entry) But is there a way to include the input field type ch...

Creating a model and related models with Inline formsets

[I have posted this at the Django users | Google Groups also.] Using the example at http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets, I am able to edit objects belonging a particular model (using modelforms). I have been trying to follow the same pattern for creating new objects using inline formsets, but ha...

In Django, how do you construct a formset manaully in a template?

I am constructing the pieces of a formset manually in a template. How do I get the hidden fields TOTAL_FORMS and INITIAL_FORMS. Is there a hidden display widget with them in it already there that I can call? <label>formset title</label> #formset.TOTAL_FORMS #formset.INITIAL_FORMS {% for form in formset.forms %} {{form.field}} {{...

Can you Make a Django form set validate the initial data?

Here's an example: from django import forms class ArticleForm(forms.Form): title = forms.CharField() pub_date = forms.DateField() from django.forms.formsets import formset_factory ArticleFormSet = formset_factory(ArticleForm) formset = ArticleFormSet(initial=my_data) So 'my_data' in the example is the data I want to form t...

Django Formset without instance

Hi. In this Django Doc explain how to create a formset that allows you to edit books belonging to a particular author. What I want to do is: Create a formset that allows you to ADD new book belonging to a NEW author... Add the Book and their Authors in the same formset. Can you gime a light? thanks. ...

Is this a bug in Django formset validation?

Manual example: http://docs.djangoproject.com/en/1.0/topics/forms/formsets/#formset-validation (I'm using Django 1.0.3 to run on Google App Engine) Code: from django import forms from django.forms.formsets import formset_factory class ArticleForm1(forms.Form): title = forms.CharField() pub_date = forms.DateField() class ArticleFo...

Django how to save a custom formset

I've written the following custom formset, but for the life of me I don't know how to save the form. I've searched the Django docs and done extensive searches, but no one solution works. Lots of rabbit holes, but no meat ;-) Can someone point me in the right direction? // views.py partial // @login_required def add_stats(request, grou...

Django: disallow can_delete on GenericStackedInline

Hello, I've built this model which contains a generic foreign key: class MyModel(models.Model): content_type = models.ForeignKey(ContentType, verbose_name=_('content type')) object_id = models.PositiveIntegerField(_('object id')) content_object = generic.GenericForeignKey('content_type', 'object_id') Next I've made a gene...

Passing Custom Form parameter to formset

Hi, I have the following Form defined class MyForm(ModelForm): def __init__(self, readOnly=False, *args, **kwargs): super(MyForm,self).__init__(*args,**kwrds) if readOnly: Do stuff to make the inputs readonly MyForm works perfectly when I instantiate it in the view as a form form = MyForm(readOnly=True...

Django formset unit test

I can't running Unit Test with formset. I try to do a test: class NewClientTestCase(TestCase): def setUp(self): self.c = Client() def test_0_create_individual_with_same_adress(self): post_data = { 'ctype': User.CONTACT_INDIVIDUAL, 'username': 'dupond.f', 'email': '...

Django formsets required

How to make all forms in django formset required? I tried to validate presence of all fields in cleaned_data overriding formset's clean() method but it just fails silently without any error displayed. Thanks! Source code: class BaseScheduleForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(BaseScheduleForm,...

Django: Initializing a FormSet of custom forms with instances

Given the following models: class Graph(models.Model): owner = models.ForeignKey(User) def __unicode__(self): return u'%d' % self.id class Point(models.Model): graph = models.ForeignKey(Graph) date = models.DateField(primary_key = True) abs = models.FloatField(null = True) avg = models.FloatField(...

Django formset doesn't validate

Hello, I am trying to save a formset but it seems to be bypassing is_valid() even though there are required fields. To test this I have a simple form: class AlbumForm(forms.Form): name = forms.CharField(required=True) The view: @login_required def add_album(request, artist): artist = Artist.objects.get(slug__iexact=artist) A...