django-forms

python django shell (ipython) unexpected behavior or bug?

流过昼夜 提交于 2020-01-03 12:22:08
问题 Django shell behaves (at least for me) unexpected when working with locale settings. Form validation of a comma separated decimal field works when calling from external script and fails on calling from django shell (ipython). Starting a new Project I got the following files: local_forms/ ├── local_forms │ ├── __init__.py │ ├── models.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── manage.py ├── my_form.py ├── test_form.py local_forms/models.py: from django.db import models class MyModel

Passing Instance to Django formset

瘦欲@ 提交于 2020-01-03 08:22:49
问题 How to pass a instance to the Django formset, The Scenario is like this. I have updated multiple rows by using a formset and, in a later stage i need to edit those values which i added earlier.(Editing) q = PaymentLines.objects.filter(pay_lines=project) formset = PayFormSet(prefix='payment', instance=q) 回答1: AuthorFormSet(queryset=Author.objects.all()) https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#changing-the-queryset 回答2: I have used it as follows the formset used is

Passing Instance to Django formset

一个人想着一个人 提交于 2020-01-03 08:22:13
问题 How to pass a instance to the Django formset, The Scenario is like this. I have updated multiple rows by using a formset and, in a later stage i need to edit those values which i added earlier.(Editing) q = PaymentLines.objects.filter(pay_lines=project) formset = PayFormSet(prefix='payment', instance=q) 回答1: AuthorFormSet(queryset=Author.objects.all()) https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#changing-the-queryset 回答2: I have used it as follows the formset used is

django: how to change values for nullbooleanfield in a modelform?

六眼飞鱼酱① 提交于 2020-01-03 07:00:09
问题 In the docs, the nullbooleanfield is represented as a <select> box with "Unknown", "Yes" and "No" choices. How can I change the values of select to some other more meaningful texts and map it back to the yes,no and unknown values in my modelform ? For example I have yes_no_required = models.NullBooleanField() and I would like to have 'yes I acknowledge this' , 'no, I do not like this' and 'I do not know now' mapping to yes, no and required accordingly. 回答1: I spent half an hour putting

Change choices attribute of model's field

淺唱寂寞╮ 提交于 2020-01-03 04:46:10
问题 This question is similar to Set model field choices attribute at run time? However, my problem is that I want to change the default value of the choices attribute, at class level. I have this class Project(models.Model): name = models.CharField(...) @staticmethod def getAllProjectsTuple(): return tuple([(p.id, p.name) for p in Project.objects.all()]) class Record(models.Model): project = models.ForeignKey( Project, verbose_name='Project', help_text='Project name', blank=True, null=True, on

Restrict user to use a specific domain to sign up : django

我们两清 提交于 2020-01-03 03:27:51
问题 I'm a Django newbie. I'd like to restrict user to use a specific domain (e.g. @gmail.com ) to sign up my Django website, but how to customize the EmailField in my registration form to do that? FYI, here's my codes. forms.py class RegistrationForm(ModelForm): username = forms.CharField(label=(u'User Name')) email = forms.EmailField(label = (u'Email Adress')) class Meta: model = UserProfile exclude = ('user',) register.html {% extends "base.html" %} {% block content %} <form action = "" method

Django form as GET

安稳与你 提交于 2020-01-03 02:28:05
问题 I want to have my site having form validation and xml generation by using GET. There will be no form rendering as HTML to fill, simply request will be a GET that parameters are generated automatically via a software. Here is my form: from django import forms class xmlRetrievalForm(forms.Form): selected_date = forms.DateField(input_formats=['%d/%m/%Y',], error_messages={'required': 'selected_date is required (ie: 29/11/2011)', 'invalid': 'selected_date field is required (ie: 29/11/2011)'})

Django User Update Form and View

谁说胖子不能爱 提交于 2020-01-03 01:37:13
问题 I am very early on in my Django/Python development journey, most things I have been able to slowly figure out after a few hours/days of head scratching and trial/error. I now have the commonly asked question that I cannot get working correctly: How Do I Create a User Profile Update View/Form? I have hacked on several solutions from Stack Overflow, and just cannot figure out what I am doing wrong thus far. Here is the initial version of my poor attempt using Django 1.9: #forms.py class

Problem with form in Django

一世执手 提交于 2020-01-02 16:23:09
问题 I'm trying to implement a form for let the user change their password. Here the code: forms.py class ChangePasswordForm(forms.Form): password1 = forms.CharField(widget = forms.PasswordInput(), required = True) password2 = forms.CharField(widget = forms.PasswordInput(), required = True) def clean_password2(self): password1 = self.cleaned_data.get("password1", "") password2 = self.cleaned_data["password2"] if password1 != password2: raise forms.ValidationError("The two password fields didn't

Passing data through a django FormWizard

懵懂的女人 提交于 2020-01-02 14:31:43
问题 I am trying to build a django form wizard to allow people to register for an event. I can get through the form wizard and see data in the done method. The problem is that I also need event_id passed into done also. How do I get event_id from the url through the form wizard and into done ? Simple example? ------- urls.py --------- named_register_forms2 = ( ('basicdata', SeatsForm), ('form2', AnotherForm), ) urlpatterns = patterns('', url(r'^register/(?P<event_id>\d+)/$', register_wizard, name=