1👍
- Create field id as charfield e.g.
string_id = models.CharField(max_length=100, default='file')
- Make a function that make string id when the model is saved.
def save(self):
new_id = self.id
self.string_id = str(new_id) + '_dot'
super(YourModelName, self).save()
0👍
You need to call super()
first.
As you can read in the documentation:
There’s no way to tell what the value of an ID will be before you call save(), because that value is calculated by your database, not by Django.
When you call super().save()
, the database engine calculates the id
(or gid
in your case, but please reconsider using the provided id
) and thus allows you to use it. Before that it is None
.
You may check this topic as well.
- [Answer]-Django modelform ForeignKey List
- [Answer]-Search criteria language parser in Python?
- [Answer]-Relational condition check in Django Rest Framework
- [Answer]-Django app engine cannot import name old_dev_appserver
Source:stackexchange.com