formset

DJANGO - Issue using formsets

北战南征 提交于 2019-12-07 13:01:00
问题 So I have a form class in my forms.py file that i will use for creating a formset with a variable number of forms (the client will set the number of forms to display). The form class would be like this: forms.py from django import forms class example(forms.Form): CHOICES = [('choice1', 'choice1'), ('choice2', 'choice2')] field1 = forms.IntegerField() field2 = forms.DateTimeField() field3 = forms.ChoiceField(choices = CHOICES) And then in my views.py file i have something like this: views.py

Django: Using Radio select box on model formsets

倖福魔咒の 提交于 2019-12-06 15:06:31
Hey, I'm using a model formset to let my users edit their photo album. I want to put a Radio select box on every photo saying "Set as cover image" so that I can process all the photos and find the one who should be album cover. The problem is how can I a field with radio select on to the formset and still keep it mutal with the rest of the photos? This is my current code: class ProjectGalleryForm(forms.ModelForm): remove_photo = forms.BooleanField() # set_as_cover_image = .... ?? <-- what to put? class Meta: model = Photo exclude = ( 'effect', 'caption', 'title_slug', 'crop_from', 'is_public',

How to show hidden autofield in django formset

淺唱寂寞╮ 提交于 2019-12-06 12:05:25
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 = MyModel fields = ('locid', 'name') it shows up on the page as, <input id="id_form-0-locid" type="hidden" value="707" name="form-0-locid"/> Thanks. Edit I create the formset like this - LocFormSet = modelformset_factory(MyModel) pformset = LocFormSet(request.POST, request.FILES, queryset

Nested and Segmented Crispy Layouts

末鹿安然 提交于 2019-12-06 06:59:06
TLDR Question: How do you make one crispy form with a ¿segmented?(not sure if this is considered inline) layout with multiple models(some related, some not). I am trying to understand several things in Django: forms, formsets, nested forms, and crispy, and I've been at it for a while, and feel I am close, just need someone to help connect the dots. I'm not sure how to accomplish it without crispy, so I started down this path thinking crispy was the solution. Please correct if I am wrong, thanks :) I would like one form (as in HTML form, not necessarily Django Form), that has a primary model

ManagementForm data missing error while formset validation

假如想象 提交于 2019-12-06 04:42:25
formset creation in views.py: ffact = formset_factory(Form,extra=somenum])) fset = ffact(prefix='pfix') validation in views.py: ffact = formset_factory(Form,extra=3)) fset = ffact(request.POST) if fset_is.valid(): blah blah this is resulting in Exception Type: ValidationError at /app/index/ Exception Value: [u'ManagementForm data is missing or has been tampered with'] django-docs did mention about this. I'm not sure how to provide management data. I tried something like this , try: fset = ffact(request.POST) except ValidationError: fset = None if fset and fset.is_valid(): blah blah But still i

Can I use multiple number of formset in a single form in django,if yes how?

末鹿安然 提交于 2019-12-06 02:06:37
问题 I have to make a form in which more than one formset is used. please tell me if this is possible. if yes then how? 回答1: You can add as many formsets in the form. Just create/init them in view and pass to template to render in the form. Something like: {{ formset1.management_form }} {% for form in formset1 %} {{ form }} {% endfor %} {{ formset2.management_form }} {% for form in formset2 %} {{ form }} {% endfor %} You are using multiple formsets in one view, you need to use prefix for the forms

Django formset cleaned_data empty when submitted form unchanged

假装没事ソ 提交于 2019-12-05 15:16:55
I've been experiencing a weird problem, regarding Django 1.4 and formsets: when the submitted data is unchanged, the cleaned_data field of the formset is empty, even if the formset itself passes the validation. Here is an example: forms.py: class NameForm(forms.Form): name = forms.CharField(required=False, initial='Foo') views.py: def welcome(request): Formset = formset_factory(NameForm, extra=1) if request.method == 'POST': formset = Formset(request.POST) print '1.Formset is valid?', formset.is_valid() print '2.Formset', formset print '3.Formset cleaned_data', formset.cleaned_data else:

Enable Django admin functionality at frontend with inlines

和自甴很熟 提交于 2019-12-05 02:52:09
I have decided to move some functionality from my admin website into the frontend. Functionality includes the administration of one model with some foreign key inlines. For that I have installed django-dynamic-formset JQuery plugin (link git ) and struggling with it already for couple of days. Here is one of the problems . The same functionality is already implemented in Django admin. I can add, modify, remove inlines and modify model instance as I want. I am wondering why should I use this JQuery plugin and why there are not so many good tutorials on the topic in the Internet? I need a good

Saving class-based view formset items with a new “virtual” column

雨燕双飞 提交于 2019-12-05 02:38:48
I have a table inside a form, generated by a formset. In this case, my problem is to save all the items after one of them is modified, adding a new "virtual" column as the sum of other two (that is only generated when displaying the table, not saved). I tried different ways, but no one is working. Issues : This save is not working at all. It worked when it was only one form, but not for the formset I tried to generate the column amount as a Sum of box_one and box_two without success. I tried generating the form this way too, but this is not working: formset = modelformset_factory( Item, form

Passing Custom Form parameter to formset

时光总嘲笑我的痴心妄想 提交于 2019-12-04 11:35:33
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, instance=ModelA) but when I try to use it in the inlineformset_factory Formset = inlineformset_factory(ModelA, ModelB form=MyForm(readOnly=True)) I get the error "NoneType object is not callable." I think this is because the form is being initialised without a model instance because MyForm is being