django-forms

Creating UpdateForm by using ModelForm in Django

坚强是说给别人听的谎言 提交于 2020-07-21 03:19:59
问题 I have a Django application and I wanna create an update form with ModelForm but I have to get the fields parameter from user_profile model. So I have created my form and view such as below. forms.py; class UpdateForm(forms.ModelForm): class Meta: model = Data fields = [] def __init__(self, *args, **kwargs): input_choices = kwargs.pop('input_choices') super(UpdateForm, self).__init__(*args,**kwargs) self.fields = input_choices views.py; @login_required(login_url = "user:login") def updateData

How do I remove Label text in Django generated form?

最后都变了- 提交于 2020-07-18 04:16:23
问题 I have a form that is displaying well only for the label text that I don't want and I have tried all I could to let it off my form but it won't just go... forms.py : class sign_up_form(forms.ModelForm): class Meta: model = Users fields =['email'] widgets = { 'email': forms.EmailInput(attrs={ 'id': 'email', 'class': 'form-control input-lg emailAddress', 'name': 'email', 'placeholder': 'Enter a valid email'})} I have tried: views.py : from django.shortcuts import render from mysite.forms import

Identify which submit button was clicked in Django form submit

非 Y 不嫁゛ 提交于 2020-07-17 07:19:11
问题 In Django I would like to have a form with 2 submit button options. "save & home" and "save & next". Any thoughts how I can identify which submit button was clicked in my view? I'm fairly new to programming/working with forms and appreciate the feedback. Form <form action="{% url 'price_assessment_section_1' component.id %}" method="post"> {% csrf_token %} {{ form.s1_q5_resin_type }} <!-- FORM SUBMIT BUTTONS--> <button type="submit" > Save&Home</button> <button type="submit" > Save&Next<

Identify which submit button was clicked in Django form submit

老子叫甜甜 提交于 2020-07-17 07:18:07
问题 In Django I would like to have a form with 2 submit button options. "save & home" and "save & next". Any thoughts how I can identify which submit button was clicked in my view? I'm fairly new to programming/working with forms and appreciate the feedback. Form <form action="{% url 'price_assessment_section_1' component.id %}" method="post"> {% csrf_token %} {{ form.s1_q5_resin_type }} <!-- FORM SUBMIT BUTTONS--> <button type="submit" > Save&Home</button> <button type="submit" > Save&Next<

Disable Choice In ModelMultipleChoiceField CheckBoxSelectMultiple Django

倾然丶 夕夏残阳落幕 提交于 2020-07-15 15:17:06
问题 All, I have researched this for a couple of days, and can't quite seem to find what I'm looking for. I am well aware of using the following to disable a field in a Django form: self.fields['author'].disabled = True The above will disable a field entirely. I am trying to display a checkbox with multiple select options, but I want one of the choices to be automatically selected and disabled so the user can not change it as one of the choices they have selected. Here is the code that I've been

form.save() not working my form.save for updating data isnt working

爱⌒轻易说出口 提交于 2020-07-14 12:06:18
问题 form.save() not working my form.save for updating data isnt working when i try to update my post it shows the original unedited post it dosent save the updated version.i donnt know whats causing the error idk if its views or anything in template if anyone could help i will be very grateful please help. here is the code: views.py from django.shortcuts import render from django.shortcuts import HttpResponseRedirect from .models import Post from .forms import PostForm def post_list(request):

form.save() not working my form.save for updating data isnt working

↘锁芯ラ 提交于 2020-07-14 12:03:39
问题 form.save() not working my form.save for updating data isnt working when i try to update my post it shows the original unedited post it dosent save the updated version.i donnt know whats causing the error idk if its views or anything in template if anyone could help i will be very grateful please help. here is the code: views.py from django.shortcuts import render from django.shortcuts import HttpResponseRedirect from .models import Post from .forms import PostForm def post_list(request):

Django forms dynamic getting author as a logged in user in model forms

给你一囗甜甜゛ 提交于 2020-07-10 09:26:27
问题 I'm trying to make some forms that will allow users to add some objects, delete them or edit but I've stucked with thing like author of model. Let's say we got model Shot which got field author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) Because I've created custom user model to expand user by some fields that I want, and then we creating modelForm, creating views etc. and finally got form. When we will try to submit this form, it won't add this object submited in

django.db.utils.IntegrityError: NOT NULL constraint failed: users_profile.user_id

烈酒焚心 提交于 2020-07-10 03:43:05
问题 I am currently working on a project that would take in a users information and store it. My problem is I keep running into this NOT NULL constraint failed with the user id error. I believe this comes from having a null user when the form is trying to save, but don't know what I could do to fix it. I tried using this line: form.user = Profile.objects.get(user=self.request.user) but it didn't work and gave me this error: NameError at /users/pii/ name 'self' is not defined Any help or advice

Why does my Django form keep saying “this field is required”

[亡魂溺海] 提交于 2020-07-09 09:30:06
问题 Does anyone know why my form (filepicker) is constantly returning "this field is required" when it worked in a simpler version? My view is def add_attempt(request, m_id, a_id): template = loader.get_template('add_attempt.html') if request.method == 'POST': import pprint pprint.pprint(request.POST) pprint.pprint(request.FILES) form = UploadAttemptForm(data=request.POST, files=request.FILES) if form.is_valid(): form.instance.pub_date = datetime.datetime.now() form.instance.user_id = request