Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
79 views
in Technique[技术] by (71.8m points)

python - Django: Create a custom order of objects in django model

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: enter image description here 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...