List Field

Table of contents

  1. Example Usage
  2. Allowed Attributes
    1. Default
    2. Required
    3. Column Name
    4. Validator
    5. Nested Field
      1. Example Usage
      2. Example Usage with NestedModelField

Array field for Firestore

Example Usage

class User(Model):
    subjects = ListField()



u = User()
u.subjects = ['English', 'Math']

Allowed Attributes

The following attributes supported by List Field.

  1. default
  2. required
  3. column_name
  4. validator
  5. nested_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

  • Nested Field

    Set nested field for list field. NestedModelField can be used to define nested model. Read More

    Example Usage

    class User(Model):
      subjects = ListField(TextField())  
      
    u = User()
    u.subjects = ['English', 'Math']
    

    Example Usage with NestedModelField

    class Message(Model):
        author = TextField()
        text = TextField()
      
    class Chat(Model):
        title = TextField()
        messages = ListField(NestedModelField(Message))
      
    Chat.from_dict({
        'title': 'Chat 1',
        'messages': [
            {
                'author': 'John',
                'text': 'Hello',
            },
            {
                'author': 'Jane',
                'text': 'Hi',
            }
        ]
    }
    

Copyright © 2019 FireO All rights reserved. Powered by OctaByte