Nisha Patel
Problem
I have these three models with two many-to-many fields in BlogPost models like
and form on the client side as follows
It allows me to select from the existing categories but not allow me to add other categories.
I want to create a form in Django that allows a user to select from the categories on the client side as well as create new categories or tags and save them to the database so that other users can select from these or search them at least.
Solution
For that, you will need to manually render a field the user can enter the name of the Category they want to create. You can access the entered value in your view, save it to the database, and add it to the Blog Post object.
Inside your HTML form tag, include:
<input type="text" name="new-category">
Then in your view, you can access and save the entered value:
Answered by: >McPherson
Credit: >StackOverflow
Blog Links:
>How to manage the Text in the container in Django?
>Fix webapp stops working issue in Django- Python webapp
>Creating a form in Django to upload a picture from the website
>Sending Audio file from Django to Vue
>How to keep all query parameters intact when changing page in Django?
>Solved: TaskList View in Django
>Implement nested serializers in the Django rest framework
>How to filter events by month in Django?
>Sorting the restframework in Django
>Ways to access instances of models in view in order to save both forms at once in Django
>What makes index.html have such kind of name in Django?
>Fix Module Not Found during Deployment- Django
>Creating a Django with existing directories, files, etc.?
>How to Read a CSV file with PHP using cURL?