Django Custom Widget For ManyToMany field - django

Does anyone know of a widget that displays 2 select boxes. One shows a list of all object in a model and the other shows the objects which have been selected. The user can then select an object from the first list, click an >> button which moves it to the 'selected' list. Then when the form is saved the objects in the selected list are saved in the manytomany field.
Thanks

django.contrib.admin.widgets.FilteredSelectMultiple

Related

Django Admin - Filter inline content depending on parent value

I have to models: "Order" and "Product"; the "Order" contains a "Customer" as foreign key.
I create an admin page where Order is the parent and products are shown as inline.
When I add a new istance of products I want that a dropdown is filtered based on the value chosen in the parent "Customer" field.
I've already tried the chained dropdown list with no success; I've also overriden the init method of the inline form but the result is the same. I can't understand what is the metod triggered when I click the "add new" link in inline formset.
Do you have any suggestion on how to achieve the result?

Django widget form for get_or_create

I have a Select widget but I need list all of values about a field of Model, and create new values of these field at the same input.
With select I can list and choose one value, but can't create news.
Whith textinput I can create but not list.
What widget form can I use?

Django ModelForm with Many to Many Field

I have a Django model for a List with a many to many field to Item, it uses a through table, that has a column for quantity.
I want to use Django forms to display a form such that the user can add items to the list. If I just try and create the ModelForm, it shows a selection box, where I can choose items, but there is no way to denote quantity for each item.
I'd like to have it display a dropdown menu where you can select an item, and an input box where you can enter the quantity.
Do I have to do something custom to get it to work this way?
EDIT: I could probably just write the form in HTML myself, but I want to use the validation features of Django forms in the backend too.
It sounds like what you want is an inline formset on the through table. That would give you the selection box for the item and the input box for the quantity.

Django admin, override dropdown with selection from popup window

In a one-to-many relationship, how can I override the drop-down menu in the change-form to be able to select value from popup window, specially when dropdown could hold a pretty long list which may slowdown the page load.
Just found the answer:
raw_id_fields is a list of fields you would like to change into an
Input widget for either a ForeignKey or ManyToManyField:
class ArticleAdmin(admin.ModelAdmin):
raw_id_fields = ("newspaper",)
https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields
The question now is how can I display a user friendly value instead of the Id returned from the popup.

Filtering a django choicefield in admin form on the basis of a value of another choicefield in the same form

In the admin form, how do you filter a django choicefield on the basis of value of another choicefield.
For example, if a choicefield is having "fruits" and "vegetables", then on selection of fruits, the second choicefield should have "apple,pear,orange" etc.Similarly one selection of vegetables the field should show "brinjal,lady finger,cabbage"
Thanks in advance
You could probably accomplish that with grouped selects in django-smart-selects. The default is outputting a drop down menu. And you should be able to modify it to output radio buttons instead.