vendredi 12 janvier 2018

Django page for selecting model instances and adding them to a list

I am a beginner with Django, and my JS/HTML/CSS knowledge is intermediate. I have two models defined in models.py: One model Product that has some basic descriptive Fields (name, description, ...), and another model Category, that has a ManyToManyField products.

I want to build a page where a user can select Products with checkboxes, and then add them to a category by pressing an "Add" button. Upon pressing, what should basically happen is:

category.products.extend( selected_products )

# This only so that I know to which category a product has been assigned, not too urgent
for product in selected_products:
    product.categories.append(category)

Here is an image of what sort of page I am aiming for:

http://ift.tt/2D7xqta

I am not asking for a full working example (unless there already happens to be one available of course). All I am looking for is some pointers on how to proceed creating this. I know how to create the list and the sidebar, but combining this with buttons per list element is new to me.

Should the proposed page be essentially 1 giant form, and should I define it in forms.py? Should I be using the Django CheckboxInput widget? Is there a recommended structure for this type of page? Links to other help pages are also greatly appreciated!




Aucun commentaire:

Enregistrer un commentaire