FAQ Database Discussion Community


How to save Django ModelFormSet?

python,django,modelform,formset
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)...

django update view with unique field

django,modelform,updatemodel
I am trying to update a phone number in a form. Two problems: It's a unique field and when I try to update it with the same phone number I get an error (this number already exists) When I save the form, it tries to blank all the other fields!...

Django form fields will not display

django,forms,modelform,django-context
I am following the Django Fundamentals tutorial on Code School and I've done pretty well understanding, following along, and figuring out my own issues as they arise, until this point. The tutorial builds a tic-tac-toe game. I am trying to add the capability to make a move when it is...

Form not showing in html - django

python,django,django-models,django-forms,modelform
I have a model that extends the User model in django, that model is a userprofile, I'll use to asociate aditional information to User model. I have the model, the form, the view, the url and the html, but the html is not showing the fiels, only shows the submit...

How to get a Django Prepopulated Model Form for User to *not* populate password

django,django-forms,modelform
I have a ModelForm for the User model that I want to use to allow the user to update some of their settings (first name, last name, email, and, of course, password). It's a very basic form and I did the UserForm(instance=user) so the user would see their current values....

Model Fomset and deletion

django,modelform,formset
I have created a modelformset usign modelformset_factory formfactory = modelformset_factory(HasJobs, form=HasJobsModelForm, can_delete=True) formset = modelformset_factory(request.POST or None) if request.method == "POST": form = AccountModelForm(request.POST, instance=account) account = form.save() for job_form in formset: instance = job_form.save(commit=False) instance.account = account instance.save() In other words I create an account using each model form...

django - custom error message for urlinput widget

python,django,widget,modelform
django 1.7 trying to customize the default client side validation message that gets fired on a model form. Specifically the error message for urlinput widget (the default for a urlfield). This error appears to come from client side validation when the form is submitted. I want to change "Please enter...

Django 1.7 modelform_factory form is always invalid with factory_boy created model

python,django,modelform,factory-boy
I'm using Django 1.7 and factory_boy to create some models. Here's the code: In models.py: class Address(models.Model): first_line = models.CharField(max_length=50, blank=True) second_line = models.CharField(max_length=50, blank=True) city = models.CharField(max_length=30, blank=True) state = models.CharField(max_length=2, blank=True) zipcode = models.CharField(max_length=5, blank=True) zipcode_ext = models.CharField(max_length=4, blank=True) The associated factory in factories.py (same directory): class...

Load data into ModelForm fields in edit mode before it rendered

django,modelform
I have a field in ModelForm that does not exist in model. The field is saved separately by overriding ModelForm.save() function: class MyForm(ModelForm): custom_field = CharField(label='Custom field', widget=TextInput()) def save(self, commit=True): data = self.cleaned_data # save custom_field Now how can I load this custom field into the ModelForm (in edit...