{"title":"Validators","version":"2.2","locale":"zh-hans","docname":"ref/contrib/postgres/validators","url":"/zh-hans/2.2/ref/contrib/postgres/validators/","canonical":"https://djangodocs.dev/zh-hans/2.2/ref/contrib/postgres/validators/","summary":"These validators are available from the django.contrib.postgres.validators module. KeysValidator Link to this heading # class KeysValidator ( keys , strict = False…","html":"<span id=\"validators\"></span><h1>Validators<a class=\"heading-anchor\" href=\"#module-django.contrib.postgres.validators\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>These validators are available from the <code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.postgres.validators</span></code>\nmodule.</p>\n<section id=\"keysvalidator\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">KeysValidator</span></code><a class=\"heading-anchor\" href=\"#keysvalidator\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.validators.KeysValidator\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">KeysValidator</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">keys</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">strict</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">False</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">messages</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">None</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.validators.KeysValidator\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Validates that the given keys are contained in the value. If <code class=\"docutils literal notranslate\"><span class=\"pre\">strict</span></code> is\n<code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, then it also checks that there are no other keys present.</p>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">messages</span></code> passed should be a dict containing the keys\n<code class=\"docutils literal notranslate\"><span class=\"pre\">missing_keys</span></code> and/or <code class=\"docutils literal notranslate\"><span class=\"pre\">extra_keys</span></code>.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>Note that this checks only for the existence of a given key, not that\nthe value of a key is non-empty.</p>\n</aside>\n</dd></dl>\n\n</section>\n<section id=\"range-validators\">\n<h2>Range validators<a class=\"heading-anchor\" href=\"#range-validators\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"rangemaxvaluevalidator\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">RangeMaxValueValidator</span></code><a class=\"heading-anchor\" href=\"#rangemaxvaluevalidator\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.validators.RangeMaxValueValidator\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">RangeMaxValueValidator</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">limit_value</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">message</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">None</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.validators.RangeMaxValueValidator\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Validates that the upper bound of the range is not greater than\n<code class=\"docutils literal notranslate\"><span class=\"pre\">limit_value</span></code>.</p>\n</dd></dl>\n\n</section>\n<section id=\"rangeminvaluevalidator\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">RangeMinValueValidator</span></code><a class=\"heading-anchor\" href=\"#rangeminvaluevalidator\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.contrib.postgres.validators.RangeMinValueValidator\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">RangeMinValueValidator</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">limit_value</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">message</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">None</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.contrib.postgres.validators.RangeMinValueValidator\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Validates that the lower bound of the range is not less than the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">limit_value</span></code>.</p>\n</dd></dl>\n\n</section>\n</section>","rootId":"module-django.contrib.postgres.validators","toc":[{"title":"KeysValidator","anchor":"keysvalidator","children":[]},{"title":"Range validators","anchor":"range-validators","children":[{"title":"RangeMaxValueValidator","anchor":"rangemaxvaluevalidator","children":[]},{"title":"RangeMinValueValidator","anchor":"rangeminvaluevalidator","children":[]}]}],"breadcrumbs":[{"docname":"ref/index","title":"API参考","url":"/zh-hans/2.2/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/zh-hans/2.2/ref/contrib/"},{"docname":"ref/contrib/postgres/index","title":"django.contrib.postgres","url":"/zh-hans/2.2/ref/contrib/postgres/"}],"prev":{"docname":"ref/contrib/postgres/search","title":"Full text search","url":"/zh-hans/2.2/ref/contrib/postgres/search/"},"next":{"docname":"ref/contrib/redirects","title":"The redirects app","url":"/zh-hans/2.2/ref/contrib/redirects/"},"formats":{"html":"/zh-hans/2.2/ref/contrib/postgres/validators/","markdown":"/zh-hans/2.2/ref/contrib/postgres/validators.md","json":"/zh-hans/2.2/ref/contrib/postgres/validators.json"},"source":"https://github.com/django/django/blob/stable/2.2.x/docs/ref/contrib/postgres/validators.txt","official":"https://docs.djangoproject.com/zh-hans/2.2/ref/contrib/postgres/validators/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}