django-forms

unable to save data using django formsets

让人想犯罪 __ 提交于 2020-03-04 20:50:36
问题 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

When editing an object in django the ImageField is not populated

偶尔善良 提交于 2020-02-27 12:04:09
问题 I'm trying to edit an existing object through a form. Every thing is working fine except for the ImageField not being populated with the current value. Here's the model: class Post(models.Model): author = models.ForeignKey(User, editable=False) slug = models.SlugField(max_length = 110, editable=False) title = models.CharField(verbose_name='Blog Title', max_length=40, blank=False) body = models.TextField(verbose_name='Body') thumbnail = models.ImageField(upload_to = 'posts/%Y/%m') Here's the

When editing an object in django the ImageField is not populated

那年仲夏 提交于 2020-02-27 12:03:22
问题 I'm trying to edit an existing object through a form. Every thing is working fine except for the ImageField not being populated with the current value. Here's the model: class Post(models.Model): author = models.ForeignKey(User, editable=False) slug = models.SlugField(max_length = 110, editable=False) title = models.CharField(verbose_name='Blog Title', max_length=40, blank=False) body = models.TextField(verbose_name='Body') thumbnail = models.ImageField(upload_to = 'posts/%Y/%m') Here's the

How would I use django.forms to prepopulate a choice field with rows from a model?

亡梦爱人 提交于 2020-02-26 18:26:26
问题 I have a ChoiceField in my form class, presumably a list of users. How do I prepopulate this with a list of users from my User model? What I have now is: class MatchForm(forms.Form): choices = [] user1_auto = forms.CharField() user1 = forms.ChoiceField(choices=choices) user2_auto = forms.CharField() user2 = forms.ChoiceField(choices=choices) def __init__(self): user_choices = User.objects.all() for choice in user_choices: self.choices.append( (choice.id, choice.get_full_name()) ) This doesn't

How would I use django.forms to prepopulate a choice field with rows from a model?

一笑奈何 提交于 2020-02-26 18:25:34
问题 I have a ChoiceField in my form class, presumably a list of users. How do I prepopulate this with a list of users from my User model? What I have now is: class MatchForm(forms.Form): choices = [] user1_auto = forms.CharField() user1 = forms.ChoiceField(choices=choices) user2_auto = forms.CharField() user2 = forms.ChoiceField(choices=choices) def __init__(self): user_choices = User.objects.all() for choice in user_choices: self.choices.append( (choice.id, choice.get_full_name()) ) This doesn't

How to match all unicode alphabetic characters and spaces in a regex?

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-25 13:44:42
问题 I am trying to validate place names in python 3/ django forms. I want to get matches with strings like: Los Angeles , Canada , 中国 , and Россия . That is, the string contains: spaces alphabetic characters (from any language) no numbers no special characters (punctuation, symbols etc.) The pattern I am currently using is r'^[^\W\d]+$' as suggested in How to match alphabetical chars without numeric chars with Python regexp?. However it only seems to match like the pattern r'^[a-zA-Z]+$ . That is

How to match all unicode alphabetic characters and spaces in a regex?

て烟熏妆下的殇ゞ 提交于 2020-02-25 13:41:06
问题 I am trying to validate place names in python 3/ django forms. I want to get matches with strings like: Los Angeles , Canada , 中国 , and Россия . That is, the string contains: spaces alphabetic characters (from any language) no numbers no special characters (punctuation, symbols etc.) The pattern I am currently using is r'^[^\W\d]+$' as suggested in How to match alphabetical chars without numeric chars with Python regexp?. However it only seems to match like the pattern r'^[a-zA-Z]+$ . That is

How to match all unicode alphabetic characters and spaces in a regex?

亡梦爱人 提交于 2020-02-25 13:40:51
问题 I am trying to validate place names in python 3/ django forms. I want to get matches with strings like: Los Angeles , Canada , 中国 , and Россия . That is, the string contains: spaces alphabetic characters (from any language) no numbers no special characters (punctuation, symbols etc.) The pattern I am currently using is r'^[^\W\d]+$' as suggested in How to match alphabetical chars without numeric chars with Python regexp?. However it only seems to match like the pattern r'^[a-zA-Z]+$ . That is

Django: ValueError at/ “The view To_do_list_app.views.home didn't return an HttpResponse object. It returned None instead.”

蹲街弑〆低调 提交于 2020-02-23 07:40:10
问题 Please, I am a newbie, if I didn't ask my question well, let me know. I am working on a To-Do List app. Anytime, I add a new task and time to the form on my web app and submit, I get the following error: ValueError at / The view To_do_list_app.views.home didn't return an HttpResponse object. It returned None instead. Below is my views.py file from django.http import HttpResponse from django.shortcuts import render,redirect from .forms import ListForm from .models import List def home(request)

Validation error not showing on form

对着背影说爱祢 提交于 2020-02-07 10:19:45
问题 I'm creating a SignUp form and it displays the validation errors, such as required fields. However, using Django-Crispy-Forms, the validation errors do not appear. I'm customizing the default form from Django-allauth, which raises ValidationError. However, using Django-Crispy forms, no errors get displayed on the form. 1.template {% extends "base.html" %} {% load i18n %} {% load crispy_forms_tags %} {% block content %} <div class="big-box"> <p><h1>{% trans "Sign Up" %}</h1></p> <p>{%