Mukesh'python-php
Mukesh'python-php

Reputation: 143

How to pre populate FilteredSelectMultiple in django admin

How to manipulate right hand side of FilteredSelectMultiplein django admin area.
OR
Is there any way to populate right hand side of FilteredSelectMultiplein django admin area.

In my scenario I want to order elements on right hand side.

Djano Model:

    class Elements(models.Model):

        movements_rel = models.ManyToOneRel('Movements','elements_rel');

        number = models.CharField(max_length=45)
        description = models.CharField(max_length=100)


    class Movements(models.Model):
        sanskrit_name = models.CharField(max_length=45)
        english_name = models.CharField(max_length=45)
        elements_rel = models.ManyToManyField('Elements',blank=True,through='Movements_Elements_Rel',verbose_name='Select Elements')

class Movements_Elements_Rel(models.Model):
    order = models.IntegerField()
    elements = models.ForeignKey('Elements')
    movements = models.ForeignKey('Movements')

can I show Elements in FilteredSelectMultiple widget with right hand side maintaining particular order

Upvotes: 2

Views: 1134

Answers (1)

matley
matley

Reputation: 341

Add

Class Meta:
  ordering = ('order',)

to Movements_Elements_Rel and the elements will appear with the particular order.

Another option is to use AdminInline in the admin to manage the manytomany relationship and use this snippet or django-grappelli. Both of them allow you to use drag-and-drop to set the particular order

Upvotes: 1

Related Questions