Text Field
Table of contents
Example Usage
class User(Model):
name = TextField()
u = User(name="Azeem")
u.save()
Allowed Attributes
The following attributes supported by DateTime Field.
-
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 likeazeem
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. Simplyformat
only work withget
andfetch
method or aftersave
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