Django의 Many to Many 관계를 through로 확장시킨 후 정렬 기준을 many to many의 특정 필드 값으로 하고 싶을 경우
class Student(models.Model):
images = models.ManyToManyField("StudentImage", related_name="students", blank=True, through="StudentImages")
class Meta:
db_table = "student"
class StudentImage(models.Model):
...
..
class Meta:
db_table = "student_image"
ordering = ('student_images_ord_no__ord_no',)
class StudentImages(models.Model):
...
..
postimage = models.ForeignKey("StudentImage", on_delete=models.CASCADE, related_name="student_images_ord_no")
ord_no = models.IntegerField(blank=True, null=True)
class Meta:
db_table = "student_images"
ordering = ("ord_no",)