Number Field

Table of contents

  1. Example Usage
  2. Allowed Attributes
    1. Default
    2. Required
    3. Column Name
    4. Validator
    5. Int Only
    6. Example Usage
    7. Float Only
    8. Example Usage
    9. Range
    10. Example Usage

Example Usage

class User(Model):
    salary = NumberField()


u = User(salary=1000)
u.save()

Allowed Attributes

The following attributes supported by DateTime Field.

  1. default
  2. required
  3. column_name
  4. validator
  5. int_only
  6. float_only
  7. range
  • Default

    Default value for field. This is base attribute that is available in all fields. Read More

  • Required

    Set True if value is required for the field. This is base attribute that is available in all fields. Read More

  • Column Name

    Set different column name in Firestore instead of field name. This is base attribute that is available in all fields. Read More

  • Validator

    Validate given value of field. This is base attribute that is available in all fields Read More

  • Int Only

Allow only integer numbers. Other than integer number it will raise error

Example Usage

class User(Model):
    salary = NumberField(int_only=True)


u = User(salary=1000)
u.save()
  • Float Only

Allow only float numbers. Other than float number it will raise error

Example Usage

class User(Model):
    salary = NumberField(float_only=True)


u = User(salary=21.37)
u.save()
  • Range

    Allow number between the range. Syntax range=(start, stop)

Example Usage

class User(Model):
    salary = NumberField(range=(100, 20000))


u = User(salary=1000)
u.save()

If you want to allow only max value set the start as None in this case there is no minimum limit

class User(Model):
    salary = NumberField(range=(None, 20000))

To allow only minimum value set the stop as None or just put the start value only

class User(Model):
    salary = NumberField(range=(100, None))  # Equivalent to range=(100)