I'm trying to build a teaching website of sorts in Django. I have a model called Test:
class Test(models.Model):
test_name = models.CharField(max_length=100)
test_directions = models.TextField(null=True)
test_status_new = models.ManyToManyField('StudentProfile', related_name='test_status_new')
test_status_good = models.ManyToManyField('StudentProfile', related_name='test_status_good')
test_status_repeat = models.ManyToManyField('StudentProfile', related_name='test_status_repeat')
test_repeat_due = models.IntegerField(default=6)
test_status_due = models.ManyToManyField('StudentProfile', related_name='test_status_due')
def __str__(self) -> str:
return f"{self.test_name}"
def __repr__(self) -> str:
return f"<{self.test_name}>"
I'd like to give them a custom ordering somehow. I am displaying them in a table like so: and would like to change the order of each individual tests from the two buttons in the Order column.
If I click Up, the test moves one row up. If I click down, the test moves down one row. How would I implement something like this?
question from:
https://stackoverflow.com/questions/65883799/django-create-a-custom-order-of-objects-in-django-model 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…