# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + tags=[] language="sh"
#
# rm -rf my_models

# + tags=[]
from datafiles import datafile

@datafile("my_models/{self.my_key}.yml")
class MyModel:

    my_key: str
    my_value: int = 0


# + tags=[]
MyModel('foo')

# + [markdown] tags=[]
# # `get_or_none(*args, **kwargs)`

# + tags=[]
MyModel.objects.get_or_none('foo')

# + tags=[]
item = MyModel.objects.get_or_none('bar')

assert item is None

# + [markdown] tags=[]
# # `get_or_create(*args, **kwags)`

# + tags=[]
MyModel.objects.get_or_create('bar', 42)

# + tags=[]
MyModel.objects.get_or_create('bar')

# + [markdown] tags=[]
# # `all()`

# + tags=[]
generator = MyModel.objects.all()

list(generator)

# + [markdown] tags=[]
# # `filter(**kwargs)`

# + tags=[]
generator = MyModel.objects.filter(my_value=42)

list(generator)

StarcoderdataJupyterScriptsDedupFiltered