Unique model field in Django and case sensitivity (postgres)

前端 未结 10 762
时光取名叫无心
时光取名叫无心 2020-12-13 13:37

Consider the following situation: -

Suppose my app allows users to create the states / provinces in their country. Just for clarity, we are considering only ASCII ch

10条回答
  •  无人及你
    2020-12-13 14:21

    a very simple solution:

    class State(models.Model):
        name = models.CharField(max_length=50, unique=True)
    
        def clean(self):
            self.name = self.name.capitalize()
    

提交回复
热议问题