Setting up the only field

Single-field can specify a unique attribute in the field, when referring to a unique combination of a plurality of fields, field name can be specified in a unique together meta specified combination, and then the data migration, only designated complete

class Links(models.Model):
    a = models.CharField('描述信息', max_length=50)
    link = models.CharField('描述信息', max_length=50, help_text='帮助显示信息')
    # 指定源类
    class Meta:
        db_table = 'links'  在数据库中的表名
        verbose_name_plural = 'xxxxx'  在后台中显示的表名
        unique_together = ('a','b')    将a,b字段进行组合拼接, 这个组合字段在表中是唯一的。不允许重复  

Guess you like

Origin www.cnblogs.com/0916m/p/11481875.html