Python django.db.models 模块,PositiveSmallIntegerField() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.db.models.PositiveSmallIntegerField()

项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def test_should_positive_small_convert_int():
    assert_conversion(models.PositiveSmallIntegerField, graphene.Int)
项目:omni-forms    作者:omni-digital    | 项目源码 | 文件源码
def test_get_concrete_class_for_model_field(self):
        """
        The get_concrete_class_for_model_field method should return the correct OmniField subclass
        """
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.CharField()), OmniCharField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.NullBooleanField()), OmniBooleanField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.BooleanField()), OmniBooleanField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.DateTimeField()), OmniDateTimeField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.DecimalField()), OmniDecimalField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.EmailField()), OmniEmailField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.FloatField()), OmniFloatField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.IntegerField()), OmniIntegerField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.BigIntegerField()), OmniIntegerField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.PositiveIntegerField()), OmniIntegerField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.SmallIntegerField()), OmniIntegerField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.TimeField()), OmniTimeField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.URLField()), OmniUrlField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.SlugField()), OmniSlugField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.FileField()), OmniFileField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.ImageField()), OmniImageField)
        self.assertEqual(OmniField.get_concrete_class_for_model_field(models.DurationField()), OmniDurationField)
        self.assertEqual(
            OmniField.get_concrete_class_for_model_field(models.GenericIPAddressField()),
            OmniGenericIPAddressField
        )
        self.assertEqual(
            OmniField.get_concrete_class_for_model_field(models.CommaSeparatedIntegerField()),
            OmniCharField
        )
        self.assertEqual(
            OmniField.get_concrete_class_for_model_field(models.PositiveSmallIntegerField()),
            OmniIntegerField
        )
        self.assertEqual(
            OmniField.get_concrete_class_for_model_field(models.ForeignKey(DummyModel2)),
            OmniForeignKeyField
        )
        self.assertEqual(
            OmniField.get_concrete_class_for_model_field(models.ManyToManyField(DummyModel2)),
            OmniManyToManyField
        )
项目:omni-forms    作者:omni-digital    | 项目源码 | 文件源码
def get_concrete_class_for_model_field(cls, model_field):
        """
        Method for getting a concrete model class to represent the type of form field required

        :param model_field: Model Field instance
        :return: OmniField subclass
        """
        field_mapping = {
            models.CharField: OmniCharField,
            models.TextField: OmniCharField,
            models.BooleanField: OmniBooleanField,
            models.NullBooleanField: OmniBooleanField,
            models.DateField: OmniDateField,
            models.DateTimeField: OmniDateTimeField,
            models.DecimalField: OmniDecimalField,
            models.EmailField: OmniEmailField,
            models.FloatField: OmniFloatField,
            models.IntegerField: OmniIntegerField,
            models.BigIntegerField: OmniIntegerField,
            models.PositiveIntegerField: OmniIntegerField,
            models.PositiveSmallIntegerField: OmniIntegerField,
            models.SmallIntegerField: OmniIntegerField,
            models.CommaSeparatedIntegerField: OmniCharField,
            models.TimeField: OmniTimeField,
            models.URLField: OmniUrlField,
            models.ForeignKey: OmniForeignKeyField,
            models.ManyToManyField: OmniManyToManyField,
            models.SlugField: OmniSlugField,
            models.FileField: OmniFileField,
            models.ImageField: OmniImageField,
            models.DurationField: OmniDurationField,
            models.GenericIPAddressField: OmniGenericIPAddressField
        }
        field_mapping.update(cls.get_custom_field_mapping())
        return field_mapping.get(model_field.__class__)
项目:eshot-api    作者:erayerdin    | 项目源码 | 文件源码
def __str__(self):
        return "{}: {} - {}".format(str(self.code), self.terminals[0], self.terminals[1])

# # http://stackoverflow.com/a/38491369/2926992
# class RouteStop(models.Model):
#     stop = models.ForeignKey(Stop)
#     route = models.ForeignKey(Route)
#     position = models.PositiveSmallIntegerField()
#
#     class Meta:
#         unique_together = (("stop", "route"))
项目:django-usda-nutrition    作者:danielnaab    | 项目源码 | 文件源码
def __str__(self):
        return '%s %s %s' % (self.amount, self.measure_description, self.food_description)


# class NutrientData(models.Model):
#     food_description = models.ForeignKey(FoodDescription, related_name='nutrient_data', help_text='5-digit Nutrient Databank number that uniquely identifies a food item. If this field is defined as numeric, the leading zero will be lost.')
#     nutrient_definition = models.ForeignKey(NutrientDefinition, help_text='Unique 3-digit identifier code for a nutrient.')
#     nutrient_value = models.DecimalField(max_digits=13, decimal_places=3, help_text='Amount in 100 grams, edible portion. (Nutrient values have been rounded to a specified number of decimal places for each nutrient. Number of decimal places is listed in the Nutrient Definition file.)')
#     number_data_points = models.PositiveSmallIntegerField(help_text='Number of data points is the number of analyses used to calculate the nutrient value. If the number of data points is 0, the value was calculated or imputed.')
#     standard_error = models.DecimalField(max_digits=11, decimal_places=3, blank=True, null=True, help_text='Standard error of the mean. Null if cannot be calculated. The standard error is also not given if the number of data points is less than three.')
#     source_code = models.ForeignKey(SourceCode, help_text='Code indicating type of data.')
#     derivation_code = models.ForeignKey(DerivationCode, blank=True, null=True, help_text='Data Derivation Code giving specific information on how the value is determined. This field is populated only for items added or updated starting with SR14. This field may not be populated if older records were used in the calculation of the mean value.')
#     ref_food_description = models.ForeignKey(FoodDescription, blank=True, null=True, help_text='NDB number of the item used to calculate a missing value. Populated only for items added or updated starting with SR14.')
#     add_nutr_mark = models.NullBooleanField(help_text='Indicates a vitamin or mineral added for fortification or enrichment. This field is populated for ready-to- eat breakfast cereals and many brand-name hot cereals in food group 08.')
#     num_studies = models.PositiveSmallIntegerField(null=True, blank=True, help_text='Number of studies.')
#     minimum = models.DecimalField(max_digits=13, decimal_places=3, help_text='Minimum value.')
#     maximum = models.DecimalField(max_digits=13, decimal_places=3, help_text='Maximum value.')
#     degrees_of_freedom = models.PositiveSmallIntegerField(null=True, blank=True, help_text='Degrees of freedom.')
#     lower_error_bound = models.DecimalField(max_digits=13, decimal_places=3, help_text='Lower 95% error bound.')
#     upper_error_bound = models.DecimalField(max_digits=13, decimal_places=3, help_text='Upper 95% error bound.')
#     statistical_comments = models.CharField(max_length=10, null=True, blank=True, help_text='Statistical comments. See definitions below.')
#     modified_date = models.CharField(max_length=10, null=True, blank=True, help_text='Indicates when a value was either added to the database or last modified.')
#     confidence_code = models.CharField(max_length=1, null=True, blank=True, help_text='Confidence Code indicating data quality, based on evaluation of sample plan, sample handling, analytical method, analytical quality control, and number of samples analyzed. Not included in this release, but is planned for future releases.')


# class DataSource(models.Model):
#     datasrc_id = models.CharField(max_length=6, primary_key=True, help_text='Unique ID identifying the reference/source.')
#     authors = models.CharField(max_length=255, null=True, blank=True, help_text='List of authors for a journal article or name of sponsoring organization for other documents.')
#     title = models.CharField(max_length=255, help_text='Title of article or name of document, such as a report from a company or trade association.')
#     year = models.CharField(max_length=4, null=True, blank=True, help_text='Year article or document was published.')
#     journal = models.CharField(max_length=135, null=True, blank=True, help_text='Name of the journal in which the article was published.')
#     vol_city = models.CharField(max_length=16, null=True, blank=True, help_text='Volume number for journal articles, books, or reports; city where sponsoring organization is located.')
#     issue_state = models.CharField(max_length=5, null=True, blank=True, help_text='Issue number for journal article; State where the sponsoring organization is located.')
#     start_page = models.CharField(max_length=5, null=True, blank=True, help_text='Starting page number of article/document.')
#     end_page = models.CharField(max_length=5, null=True, blank=True, help_text='Ending page number of article/document.')


# class DataSourceLN(models.Model):
#     #ndb_no = models.ForeignKey(NutrientData, max_length=5, help_text='5-digit Nutrient Databank number that uniquely identifies a food item. If this field is defined as numeric, the leading zero will be lost.')
#     #nutr_no = models.ForeignKey(max_length=3, help_text='Unique 3-digit identifier code for a nutrient.')
#     #datasrc_id = models.ForeignKey(max_length=6, help_text='Unique ID identifying the reference/source.')



# class LanguaLDescription(models.Model):
#     """
#     http://www.langual.org/
#     """
#     pass


# class LanguaL(models.Model):
#     pass