1

I have a Django app. Pretty basic one at that.

In the model I have a class for items and a class for groups. The groups has a many to many for the items:

items = models.ManyToManyField(item, verbose_name="list of items", max_length=100000, blank=True)

When I add this to the admin section I would like to have a checkbox with multiple select. Is this possible. All of the solutions I have looked at don't sow it in the context of an admin page too. The Django admin page is all I need it to work on as I am not making any custom, public facing pages.

What is the easiest and most simple solution to replace the multiple select box with a multiple checkbox.

PS. I am relatively in-experienced with Django so I need to see what I need to import in the model and admin.

Thanks

1
  • I still can't get it to work so I have decided that for now I will use: filter_horizontal = ('items',) Commented Mar 1, 2011 at 14:25

2 Answers 2

3

If you know how to do it for a standard modelform, you know how to do it in an admin page too, as they are based on normal forms.

Just define the form as normal, then tell the admin to use it for your model:

class MyModelAdmin(admin.ModelAdmin):
    form = MyFormWithTheMultipleSelect
Sign up to request clarification or add additional context in comments.

Comments

1

way based on overriding admin templates

/myproject/templates/admin/myapp/mymodel/change_form.html

{% extends "admin/change_form.html" %}
{{ block.super }} 
<script type='text/javascript' src='/media/js/jquery.js'></script>
<script>
    $(document).ready(function(){
        myselect = $("#id_M2M_FIELD_NAME");

        // here you manipulating with your multiple select,
        // and convert it to checkboxes, or something else.   

    })
</script>
{% endblock %}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.