formset

unable to save data using django formsets

让人想犯罪 __ 提交于 2020-03-04 20:50:36
问题 The data entered in the form is not saving in the database and it is not showing any errors. Iam trying to create an exam with atleast one question, using ExamModelForm and QuestionFormset. After entering exam details and questions in create_exam_with_questions.html, the create button is not saving the data into the database views.py from django.shortcuts import render from django.shortcuts import redirect from django.http import HttpResponseRedirect, HttpResponse from .forms import

django formset not validating because ID is required

安稳与你 提交于 2020-02-03 08:10:25
问题 MY view receives a model formset from the template, but it doesn't pass validation, claiming that ID is required. Al my use of forms until now has never brought up this problem, and I've never had to pass ID's around. Here is a simplified version of my view: def BudgetView(request): import pdb pdb.set_trace() if request.user.is_authenticated: U=request.user #initalize formset factories ItemFormSet = modelformset_factory(Item, fields=(blabla), extra=0) CatFormset=modelformset_factory

Django formset cleaned_data empty when submitted form unchanged

血红的双手。 提交于 2020-01-13 11:46:06
问题 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

Django formsets required

你说的曾经没有我的故事 提交于 2020-01-03 15:59:13
问题 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, self).__init__(*args, **kwargs) self.fields['day'].widget = forms.HiddenInput() self.fields['user'].widget = forms.HiddenInput() class Meta: model = Schedule def clean_end

Nested and Segmented Crispy Layouts

╄→尐↘猪︶ㄣ 提交于 2020-01-02 13:44:50
问题 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,

Model Formset - By Default model formset is rendering one extra field (2 fields in total)

随声附和 提交于 2020-01-01 14:45:13
问题 My model formset without even defining "extra" parameters in modelformset_factory is rendering one extra field in the template. I have tried many variations but it didn't work. If I print the form (the model form) on the command line it just prints a single form field as required but on model formset it prints 2 by default. Here is my code. models.py class Direction(models.Model): text = models.TextField(blank=True, verbose_name='Direction|text') forms.py class DirectionForm(forms.ModelForm):

Django: How to save a formset based on two models

不打扰是莪最后的温柔 提交于 2020-01-01 12:03:21
问题 I am having difficult times saving a formset to the database. I have 2 models, one having a ForeignKey to the other(I made some entries for Balanta model in Django admin page): models.py class Balanta(models.Model): data=models.DateField() class Meta: ordering=['data'] verbose_name_plural="Balante" def __unicode__(self): return unicode(self.data) class Conturi(models.Model): cont=models.PositiveIntegerField() cont_debit=models.DecimalField(default=0, max_digits=30, decimal_places=2) cont

Django formset doesn't validate

依然范特西╮ 提交于 2019-12-30 04:32:26
问题 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) AlbumFormSet = formset_factory(AlbumForm) if request.method == 'POST': formset = AlbumFormSet(request.POST, request.FILES) if formset.is_valid(): return HttpResponse('worked')

Django Formset.is_valid() failing for extra forms

雨燕双飞 提交于 2019-12-30 01:52:25
问题 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 have A = 0 B = 1 C = 2 D = 3 choices = ((A, 'Aah'), (B, 'Baa'), (C, 'Caa'), (D, 'Daa')) # This is a required choice field pickme = forms.ChoiceField(choices=choices)

Inline formset returns empty list on save?

我们两清 提交于 2019-12-25 01:32:23
问题 When I try to save my inline formset it just returns an empty list and no changes are reflected in the database. I have tried doing it with no option and commit=False but they both have the same result. I know there is data because I printed the formset as a table, and I know it is valid because the property is_valid() method returns true. Here is the code: def edit(request): if request.method == 'POST': print(request.POST) form = TombstoneForm(request.POST) print(form.is_valid()) t = form