Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: (Django)从 charField 中修剪空格
在 ruby on rails 中,在保存模型时非常容易去除空格。在 django 中,最佳做法是什么?
覆盖方法非常容易models.Model save,以执行任何预 svae 操作。该链接stummjr还提供了一个示例。
models.Model
save
stummjr
class MyClass(models.Model): # some fields here def save(self, *args, **kwargs): # strip spaces here super(MyClass, self).save(*args, **kwargs) # make sure to call parent save method ^