Explicit ordering for Lesson, Question, Choice (+id tie-break on Unit/Node): lessons no longer reshuffle after row updates
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -101,7 +101,7 @@ class Unit(models.Model):
|
||||
order = models.PositiveIntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
ordering = ['order']
|
||||
ordering = ['order', 'id']
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
@@ -117,7 +117,7 @@ class Node(models.Model):
|
||||
order = models.PositiveIntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
ordering = ['order']
|
||||
ordering = ['order', 'id']
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
@@ -156,6 +156,12 @@ class Lesson(models.Model):
|
||||
|
||||
mascot_animation = models.CharField(max_length=50, default='explain')
|
||||
|
||||
class Meta:
|
||||
# بدونِ ORDER BY، Postgres سطرها را به ترتیبِ فیزیکی برمیگرداند و هر UPDATE (ویرایشِ ادمین،
|
||||
# seed_content) آن را جابهجا میکند: درسِ اول یک جزیره عوض میشد (گزارشِ مالک ۲۰۲۶-۱۰-۱۵).
|
||||
# seed درسها را به ترتیبِ فایل میسازد، پس ترتیبِ id همان ترتیبِ کتاب است.
|
||||
ordering = ['id']
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
@@ -171,6 +177,9 @@ class Question(models.Model):
|
||||
# null یعنی سوال شکل ندارد. هنگامِ نمایش هیچ فراخوانیِ مدل نیست؛ فرانت فقط میکشد.
|
||||
figure = models.JSONField(null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
|
||||
def __str__(self):
|
||||
return self.prompt[:50]
|
||||
|
||||
@@ -181,6 +190,9 @@ class Choice(models.Model):
|
||||
value = models.CharField(max_length=300)
|
||||
is_correct = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user