Text Field

Table of contents

  1. Example Usage
  2. Allowed Attributes
    1. Default
    2. Required
    3. Column Name
    4. Validator
    5. Max Length
    6. Example Usage
    7. Lower case
    8. Format

Example Usage

class User(Model):
    name = TextField()


u = User(name="Azeem")
u.save()

Allowed Attributes

The following attributes supported by DateTime Field.

  1. default
  2. required
  3. column_name
  4. Lowercase
  5. validator
  6. max_length
  7. format
  • 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

  • Max Length

Maximum length for TextField.

Example Usage

class User(Model):
    name = TextField(max_length=3)


u = User(name="Azeem")
u.save()

print(u.name)  # Aze
  • Lower case

    Firestore is case sensitive if you save name as Azeem you can’t filter it like azeem So it is best practice to save data in lower case it help you to search easily. FirO allow to save data in lower case and search data without case sensitive.

Example Usage

class User(Model):
    name = TextField(to_lowercase=True)
    age = NumberField()


User.collection.create(name='Azeem', age=26)


# Filter result All three are works and give same result
User.collection.filter('name', '==', 'azeem').get()
User.collection.filter('name', '==', 'Azeem').get()
User.collection.filter('name', '==', 'AzEEm').get()
  • Format

    FireO allow to format text in different type, possible format type are title, upper, lower, capitalize format only work when you get data from Firestore. These are not work on saving data. format=upper will not save the data in uppercase instead it will get data from Firestore and convert it in to uppercase. Simply format only work with get and fetch method or after save method.

Example Usage

class User(Model):
    name = TextField(format='upper')

u = User()
u.name = "it's my name"
u.save()

print(u.name) # IT'S MY NAME

Example with get()

class User(Model)
    name = TextField(format='title')

u = User.collection.get(user_key)
print(u.name) # It's My Name

Copyright © 2019 FireO All rights reserved. Powered by OctaByte