I have added order_with_respect_to in a Model. How to set order through admin?

Hi all,

I have a model named Activity, and a set of ActivitySteps:

class Activity(models.Model):
    name = models.CharField(max_length=512, default=None)

class ActivityStep(models.Model):
    name = models.CharField(max_length=512, default=None)
    activity = models.ForeignKey('Activity', on_delete=models.CASCADE, default=None, null=False, blank=False)
    class Meta:
        order_with_respect_to = "activity"

Now my question is:
Is there an admin interface that will allow to set the ordering of steps in activities through the admin UI?

I’m not aware of any Django-provided solution for this.

You might want to look at third-party packages that may provide this feature. Check out djangopackages.org for some possibilities. (See django-admin-sortable2)

If you don’t find anything suitable, you can implement one yourself.

It would need to be some type of JavaScript widget to allow for the ordering of the fields combined with something in Django that expects that order and knows what to do with it.

That implies to me that it would need to be implemented in a custom form using that JavaScript widget, with an overridden save_model method to call the set_RELATED_order method.

Even if you don’t want to use an existing third-party-package, it would probably be worth your time to read the code to see how they work.