django-forms

Django View Class : name 'self' is not defined

∥☆過路亽.° 提交于 2019-12-25 04:49:16
问题 I'm working on the Django framework. Now I'm making a Class for user registration like below. I got a error on the line number 6. Could you give some help? 1: class JoinForm(forms.Form): 2: MONTH = { 3: 1:('Jan'), 2:('Feb'), 3:('March'), 4:('Apl'), 5:('May'), 6:('Jun'), 4: 7:('July'), 8:('Aug'), 9:('Sep'), 10:('Oct'), 11:('Nov'), 12:('Dec') 5: } 6: YEAR = self.makeYearChoice(self,1940) 7: email = forms.EmailField(label='Email Address', max_length=50) 8: name = forms.CharField(label='Real Name

How can I use instance data in form validation in Django?

二次信任 提交于 2019-12-25 04:45:10
问题 I am trying to make sure a list name is unique for a certain user. Here is my view: list = List(user=user) new_list_form = ListForm(request.POST, instance=list) if new_list_form.is_valid(): new_list_form.save() And here is the validator that cleans the title (the name of the list): def clean_title(self): title = self.cleaned_data['title'] if List.objects.get(user=user, title=title): raise forms.ValidationError("List title must be unique.") return title Which doesn't work because 'ListForm'

remove the default select in ForeignKey Field of django admin

心已入冬 提交于 2019-12-25 04:25:44
问题 There are 150k entries in User model. When i am using it in django-admin without the raw_id_fields it is causing problem while loading all the entries as a select menu of foreign key. is there alternate way so that it could be loaded easily or could become searchable? I have these models as of defined above and there is a User model which is used as ForeignKey in ProfileRecommendation models. The database entry for user model consist of around 150k entries. I don't want default select option

Unable to get post data in a multipleChoiceField with django

白昼怎懂夜的黑 提交于 2019-12-25 04:05:10
问题 I have a form with some checkBoxes and some text, when the user submit the data I use the following form object: class PostForm(forms.Form): product = forms.MultipleChoiceField( label='product', widget=forms.CheckboxSelectMultiple) text = forms.CharField(label='text', max_length=1000) def __init__(self, choices, *args, **kwargs): super(PostForm, self).__init__(*args, **kwargs) self.fields['product'].choices = choices But when I debug the code, the post cleaned_data is totally empty, and the

call a function from django-form without rendering its view

和自甴很熟 提交于 2019-12-25 04:03:07
问题 using Django I want to create a website on which if you click a button, a function is called in the server. And I also want a following condition: after the button is clicked, the page will not to be re-rendered. In a simpler word, I want to button-click and the run python script in the server. I've created the button-and-call-function script as follows, but it causes error because returned value is 1 and not rendering function. How can I achieve the goal? app_name/templates/app_name/index

Add div wrapper to each select in SelectDateWidget

佐手、 提交于 2019-12-25 03:53:58
问题 Is it possible to overwrite SelectDateWidget to wrap a div around each select? Like this: <div class="wrapper"> <select class="selectdatewidget form-control" id="id_birthdate_day" name="birthdate_day"> <option value="0">---</option>.... </select> </div> <div class="wrapper"> <select class="selectdatewidget form-control" id="id_birthdate_month" name="birthdate_month"> <option value="0">---</option>.... </select> </div> <div class="wrapper"> <select class="selectdatewidget form-control" id="id

dynamic form requirements from model

落爺英雄遲暮 提交于 2019-12-25 03:42:11
问题 I'm trying to generate a dynamic registration form, based on on specific client needs. I've created a UserProfile model with most of the fields set as blank=True. When the form gets generated, I pull the client specified fields from another db table and generate the registration form. All this works, except that all the fields allow blank values. So far I have this def RegProfileForm(include_list, *args, **kwargs): class ProfileForm(forms.ModelForm): class Meta: model = hr.UserProfile fields

Django REST Framework: rendering form elements in list response

寵の児 提交于 2019-12-25 03:12:32
问题 How can Django REST Framework be used to render a list of model instances with specific fields editable by the user? I'm a few months into Django, and only a couple days into DRF. I've tried several different approaches, but just can't seem to wrap my head around it. Prior to using DRF, my workflow would have been to set up a view (and associated URL) that: queried my model, picked my custom form from forms.py (exposing only the fields I needed), put the two together into a dictionary, and

get a multiple choice queryset in Django view and save it

久未见 提交于 2019-12-25 03:12:08
问题 I have a multiple choice field with a foreign key. I want to save which keeper was attending a training session and I want to list all keepers as a multiple choice field. class AddAttendance(forms.ModelForm): attendanceKeeper = Attendance.objects.only("keeper","present").all() keeperValues = Attendance.objects.values_list("keeper__id", flat=True).distinct() keeper = forms.ModelMultipleChoiceField(widget=forms.widgets.CheckboxSelectMultiple, queryset=Keeper.objects.filter(id__in=keeperValues,

How to create 'child' questions in Django forms?

给你一囗甜甜゛ 提交于 2019-12-25 02:37:12
问题 I would like to know how to create 'child' questions using Django forms. Thats is, questions which are only visible depending on the answer provided in a preceding question. I'm fairly sure I'm not using the correct terminology with the term 'child' questions but I am sure someone will figure out what I mean In the below example, when the user selects "United States of America" The option to select which state they are from should become visible. This would be standard on my website forms. Is