如何更新 Django 中的 id 字段,例如我有这个:
mysql> SELECT * FROM school_subjects;
+----+--------+---------+-------------+
| id | name | user_id | delete_flag |
+----+--------+---------+-------------+
| 1 | Canada | 2 | 0 |
| 2 | USA | 2 | 0 |
+----+--------+---------+-------------+
如果我删除它们,然后再次更新,我的 id 将不断增加:
mysql> SELECT * FROM school_subjects;
+----+--------+---------+-------------+
| id | name | user_id | delete_flag |
+----+--------+---------+-------------+
| 3 | Canada | 2 | 0 |
| 4 | USA | 2 | 0 |
+----+--------+---------+-------------
+ 那么如何让 id 字段检查最低的字段,然后从那里增加呢?
#models.py
class Subjects(models.Model):
""" Subject Database """
name = models.CharField(max_length=64, unique=False) #Subject Names on left-menu
user = models.ForeignKey(User, unique=False)
delete_flag = models.BooleanField(default=False)
def __unicode__(self):
return '%s %s' %(self.name, self.user.username)