Previous title: Unable to import ‘misaka’ – Django I am following a tutorial about how to build a social network. I run into this error: IntegrityError at /posts/new/ NOT NULL constraint failed: posts_post.user_id Complete traceback (please note the lines in bold): The lines in bold are pointing to these two pieces of code: 1: In my_projectpostsviews.py in form_valid: 2: In
Tag: django-forms
TypeError: __init__() got an unexpected keyword argument ‘choices’
forms.py Answer This is a form. A form deals with interacting with the user. An IntegerField of forms has no choices. After all the IntegerField of models deals with how we store data in the database. You can use a TypedChoiceField [Django-doc] for this:
how to check if a string fullfil with multiple regex and capture that portion that match?
What I want I’m working with a django form and it takes a password input. I need to pass the input value for multiple regexes, which will test if: at least one character is a lowecase at least one character is a uppercase at least one character is a number at least one character is a especial character (symbol) 8
form for simultaneously editing two django models with foreign key relationship
I am trying to find a simple way to create a form that allows the editing of two models with foreign key relationship simultaneously. After some research, it seems that Inline formsets come very close to what I want to do. The django documentation offers this example: And then, Let’s suppose Author has a second field, city. Can I use
Pass argument to Django form
There are several questions on stackoverflow related to this topic but none of them explains whats happening neither provides working solution. I need to pass user’s first name as an argument to Django ModelForm when rendering template with this form. I have some basic form: Here’s my sample class-based view: What do I pass to MyForm when initialising it and
Specifying both ‘fields’ and ‘form_class’ is not permitted
I have the following form, which I want render it with Django crispy forms. This is my views.py This is my urls.py project main file : This is my medical_encounter_information/urls.py In my forms.py file I have: The template medical_encounter_information/templates/medical_encounter_information/rehabilitationsession_form.html is: When I type in my browser the url http://localhost:8000/sesiones-de-rehabilitacion/nuevo/ I get the following: But, When I type in my browser
Specify max and min in NumberInput widget
I have a form that is using NumberInput widget to accept a rating for a Song from the user. The number should be between 0-5. My Song model has a MaxValueValidator but I want the NumberInput widget to show options only from 0-5. Answer In your form you can add min and max value which atleast shows the user the
Django forms.DateInput does not apply the attributes given in attrs field
Placeholder, class not getting set when tried to apply through the django’s attrs specifier for forms.DateInput The form is a ModelForm. And according to the docs Takes same arguments as TextInput, with one more optional argument: Here is the code : The same is applied for a forms.TextInput and it works just fine. What am I missing here? Just anybody
What is the equivalent of “none” in django templates?
I want to see if a field/variable is none within a Django template. What is the correct syntax for that? This is what I currently have: In the example above, what would I use to replace “null”? Answer None, False and True all are available within template tags and filters. None, False, the empty string (”, “”, “”””””) and empty
Django form – set label
I have a form that inherits from 2 other forms. In my form, I want to change the label of a field that was defined in one of the parent forms. Does anyone know how this can be done? I’m trying to do it in my __init__, but it throws an error saying that “‘RegistrationFormTOS’ object has no attribute ’email'”.