如何更新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)