TTT
TTT

Reputation: 6896

Pre-check Django admin checkboxes

Consider a Django Admin changelist view looking somewhat like this:

enter image description here

I would like to pre-check some of the checkboxes in the list. Documentation didn't help me further.

Any ideas on how to achieve this in a nice way? Where by nice I mean, as standard as possible.

Upvotes: 4

Views: 469

Answers (1)

Alasdair
Alasdair

Reputation: 308999

You could tick the checkboxes using JavaScript. For example, to tick the checkbox for the item with primary key 1, using jQuery, you would do:

$(".action-select[value='1']").prop('checked', true);

Or you could use Django's bundled jQuery if you want:

django.jQuery(".action-select[value='1']").prop('checked', true);

Upvotes: 2

Related Questions