formset

How to save Django ModelFormSet?

亡梦爱人 提交于 2021-02-07 20:31:37
问题 I'm quite desperate now and I cannot figure this out. To me it should be easy to do, but I have not come across any answers that explains this. Two models with no foreign keys between them: class Employee(models.Model): surname = models.CharField(max_length=100) name = models.CharField(max_length=100) class Salary(models.Model): date = models.DateField(auto_now_add=True) surname = models.CharField(max_length=100) name = models.CharField(max_length=100) salary = models.DecimalField(max_digits

Custom Label in Django Formset

与世无争的帅哥 提交于 2021-02-06 11:41:04
问题 How do I add custom labels to my formset? <form method="post" action=""> {{ formset.management_form }} {% for form in formset %} {% for field in form %} {{ field.label_tag }}: {{ field }} {% endfor %} {% endfor %} </form> My model is: class Sing(models.Model): song = models.CharField(max_length = 50) band = models.CharField(max_length = 50) Now in the template instead of the field label being 'song' , how do i set it so that it shows up as 'What song are you going to sing?' ? 回答1: You can use

inline formset only save the last form

只愿长相守 提交于 2020-07-04 03:46:16
问题 i tried many ways and searched alot(googled) but no one worked for me . whenever i save my inlineformset it only save the last form , my models.py class Book(models.Model): book = models.CharField(max_length=20,unique=True) author = models.ForeignKey(Author,on_delete=models.CASCADE) class Author(models.Model): author = models.CharField(max_length=30,unique=True) count = models.IntegerField() this is my forms.py class AuthorForm(ModelForm): class Meta: model = Author fields = ['author','count'

inline formset only save the last form

巧了我就是萌 提交于 2020-07-04 03:44:56
问题 i tried many ways and searched alot(googled) but no one worked for me . whenever i save my inlineformset it only save the last form , my models.py class Book(models.Model): book = models.CharField(max_length=20,unique=True) author = models.ForeignKey(Author,on_delete=models.CASCADE) class Author(models.Model): author = models.CharField(max_length=30,unique=True) count = models.IntegerField() this is my forms.py class AuthorForm(ModelForm): class Meta: model = Author fields = ['author','count'

django - formset

故事扮演 提交于 2020-06-23 14:16:11
问题 please someone can explain for me a bit more about formset with its template , all my formsets only save the last form a appreciate your helps class Name(models.Model): name = models.CharField(unique=True,max_length=50) date = models.DateTimeField(auto_now_add=True) def __str__(self): return self.name forms.py class NameForm(ModelForm): class Meta: model = Name fields = '__all__' NameFormSet = modelformset_factory(Name,form=NameForm,extra=1,max_num=10) my template <button class="btn-block mt

Initialize a formset

笑着哭i 提交于 2020-05-29 07:48:57
问题 I have two models connected by manytomany relationship and I am trying to use formset to create a dynamic form. I am able to save the form but the problem arise when I am trying to edit the saved instance, I don't know how to properly pass the instance to the formset such that it shows the instance data in form for editing Here are the details: Models.py class Player(models.Model): pname = models.CharField(max_length=50) hscore = models.IntegerField() age = models.IntegerField() def __str__

unable to save data using django formsets

删除回忆录丶 提交于 2020-03-04 20:51:01
问题 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

unable to save data using django formsets

好久不见. 提交于 2020-03-04 20:50:53
问题 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