I want to dynamically create multiple dropbox fields as I input the number of fields to be created.
For instance, there are 2 fields:
integer input field
dropdown menu
so when I input(let's say "4" in field 1) then 4 dropdowns should be created.
How should it be done? And upon submitting the form the same will be stored as a list in a database (flask is used at the backend).
Please guide.
Thanks in advance.
Flask is rather lightweight framework so to create fields dynamically use Javascript. Note nowadays its preferred to develop websites using some advanced JS library or 'framework' JQuery, vue, react etc. On backend you create a controller to save the data. Start with going though a tutorial to understand the procedure. https://www.youtube.com/watch?v=6N4OmsfwfdU . If you use WTF find a tutorial or discussion specific to WTF.
Related
I am trying to create a simple, Django-based To-do web app. Each task in the app will be linked to tags.
I can achieve the above by creating models for both the tasks and the tags with many:many relationship. When I create the form for user to create new tasks (using ModelForm), they are also offered up a a way to multi-select tags.
All of the above is fine. However, I am trying to figure out a way
to give the user the ability to ‘create’ new tags when they’re creating new tasks as well.
Ability for user to enter comma separated tags that get added to db as individual ‘tag’ objects.
Can this also be done while retaining the choice for users to select from existing tags?
How do I achieve any or all of this? Any help would be much appreciated. Thanks!
1- you need a button like + in django admin when user click on that show dropdown or something and get tags from user and update your tag list in the tasks form ( with ajax or something else )
2- i think this is can archieve with frontend 🤔 search for select2 library.
But if you want user send tag1, tag2, tag3 you can use .split(",") in your view to get each tag and save on db.
I am trying to create a python gui application where I need an MVC like pattern to display and control models.
My issue is that I will create and modify the models over time and I need to create several different "view types" (like a form view on one window and a map view on an other), each "view type" should be able to show each of my models.
If I use an MVC pattern (which I am not even sure is relevant), I should then create a view-controller for each of my model and "view type".
So if I create a new model, I will have to create a view-controller for each of the existing "view types", and if I want to create a new "view type" I will have to create a new view-controller for each model.
Creating a generic view is hard because the models are quite independant and differents.
Is there a good pattern or example I could use so I can make this smarter ? I'm stuck with this model / view design...
Thanks for ideas.
I believe you can this by using MVC. You don't have to create a lot of controllers for each model, you can just design GET-parameter like ?view= or specify endpoint to read view type and after this to handle it in a single controllers.
I have a Django and i want to create CRM system, allowing users to view, add, delete and edit data in a front-end. I found nice module, named django-tables2, which allows displaying nice tables of my data:
django-tables2 turns data into HTML tables. Features:
Pagination Ordering Extendable Class based view Supports for queryset
and list data Themes
So my question is what is the best way to make front-end editing with this tables?
For example: i want to make records from table be selectable with checkboxes and then i want them to be deletable and editable, like in django built-in admin. In other words: i need some tool like django-admin but in my front-end (in my template).
So do i need to write js to handle user clicks on table records and point this actions to my urls/views or there is a better way?Hope this question will help not only my but anyone who planning to became frontend-ninja, THANKS!
I think you should take a look at Swampdragon and Angular. They might integrate nicely with django-tables2. You can always just write the table with Angular.
I am new in django (and python as well).
I want to have a dependent select field for state and city in admin . I know the feature Grouped Selects in django smart selects can do this. But this method render the options from the database which is not what I looking for.
I have the dependent data from the external source (json format), and using javascript to populate the regarding data.
So, how do I create the select field and add a class to it (for js selector)?
should I create a empty text field and using js to convert it to select field?
Thanks
I would consider using django autocomplete light, it is a fairly solid select-field chaining tool that is good for both model relationships and remote data sources.
This is a link to the documentation for the remote data integration.
http://django-autocomplete-light.readthedocs.org/en/latest/remote.html
I've been searching stack overflow and google for a solution for over an hour now, and I can't seem to find something that, in my opinion, should be easy to obtain (as it's a common use case).
I've checked this thread, and a few others, but I haven't been able to find a real, easy solution:
Django modelform: is inline adding related model possible?
Anyway, say I have a model with three related entities, two foreign keys and a many-to-many related class. Now, I have a ModelForm which displays these in comboboxes and lists, but what I need is that "+" button next to these elements (as seen in the admin interface).
I want the plus to take me to a new form, for that particular entity, allow me to submit the new information, create the database entry, take me back to my original form and have the newly added entity selected in the combobox. I'm really hoping the django ModelForm Meta class has an attribute that I can't seem to find which enables exactly this.
This isn't really a django question.
This has to do with presentation of a particular widget in an html document, and that is governed by either the HTML markup, CSS, or javascript.
Django is a server side application and is primarily responsible for creating a valid http response and receiving a valid http request (of course, there is a lot that happens in the interim and that is why django is so big) but it's not a "one toolkit to kill them all" app.
I think you want to look at bootstrap: http://getbootstrap.com/
Jquery UI: http://jqueryui.com/
Or some combination of the two.
You can also just mark up the document yourself with a stock img or something.
However, if you want to do it exactly how the admin does it, just go into django.contrib.admin and examin the code to figure out how the django developers did it. I believe they are just using Jquery UI and some manual markup to accomplish that.