class Book(LibraryBook): class Meta: key_field_name = 'isbn' title = odin.String() isbn = odin.String() num_pages = odin.Integer() rrp = odin.Float(default=20.4, use_default_if_not_provided=True) fiction = odin.Boolean(is_attribute=True) genre = odin.String(choices=( ('sci-fi', 'Science Fiction'), ('fantasy', 'Fantasy'), ('biography', 'Biography'), ('others', 'Others'), ('computers-and-tech', 'Computers & technology'), )) # published = odin.TypedArrayField(odin.DateTimeField()) # authors = odin.ArrayOf(Author, use_container=True) # publisher = odin.DictAs(Publisher, null=True) def __eq__(self, other): if other: return vars(self) == vars(other) return False
class Subscriber(odin.Resource): name = odin.String() address = odin.String() def __eq__(self, other): if other: return self.name == other.name and self.address == other.address
class OldBook(LibraryBook): name = odin.String(key=True) num_pages = odin.Integer() price = odin.Float() genre = odin.String(key=True, choices=( ('sci-fi', 'Science Fiction'), ('fantasy', 'Fantasy'), ('biography', 'Biography'), ('others', 'Others'), ('computers-and-tech', 'Computers & technology'), )) published = odin.DateTime()
class ToResource(odin.Resource): # Auto matched title = odin.String() count = odin.Integer() # child = odin.ObjectAs(ChildResource) # children = odin.ArrayOf(ChildResource) # Excluded excluded1 = odin.Float() # Mappings to_field1 = odin.String() to_field2 = odin.Integer() to_field3 = odin.Integer() same_but_different = odin.String() # Custom mappings to_field_c1 = odin.String() to_field_c2 = odin.String() to_field_c3 = odin.String() not_auto_c5 = odin.String() # array_string = odin.TypedArray(odin.StringField()) assigned_field = odin.String()
class Library(odin.Resource): name = odin.String() # books = odin.ArrayOf(LibraryBook) # subscribers = odin.ArrayOf(Subscriber, null=True) book_count = odin.Calculated(lambda o: len(o.books))
class Author(odin.Resource): name = odin.String() class Meta: name_space = None
class InheritedResource(FromResource): # Additional fields name = odin.String() # Additional virtual fields calculated_field = odin.Calculated(lambda obj: 11)
class Publisher(odin.Resource): name = odin.String() class Meta: name_space = None
class FromResource(odin.Resource): # Auto matched title = odin.String() count = odin.String() # child = odin.ObjectAs(ChildResource) # children = odin.ArrayOf(ChildResource) # Excluded excluded1 = odin.Float() # Mappings from_field1 = odin.String() from_field2 = odin.String() from_field3 = odin.Integer() from_field4 = odin.Integer() same_but_different = odin.String() # Custom mappings from_field_c1 = odin.String() from_field_c2 = odin.String() from_field_c3 = odin.String() from_field_c4 = odin.String() not_auto_c5 = odin.String() comma_separated_string = odin.String() # Virtual fields constant_field = odin.Constant(value=10)
class ChildResource(odin.Resource): name = odin.String()