class Quest(Document): name = fields.StringField(unique = True, requied = True, allow_null = False) description = fields.StringField() quest_types = fields.ListField(fields.StringField()) start = fields.GeoPointField() rating = fields.FloatField() locations = fields.ListField() #тип не определён tags = fields.ListField(fields.StringField())
class GeoDoc(Document): geo_point_field = fields.GeoPointField() point_field = fields.PointField() line_field = fields.LineStringField() poly_field = fields.PolygonField() multi_point_field = fields.MultiPointField() multi_line_field = fields.MultiLineStringField() multi_poly_field = fields.MultiPolygonField()
class UserPreferences(mongoengine.Document): user_id = fields.IntField(required=True) home_location = fields.GeoPointField(required=True) radius_in_meters = fields.IntField(required=True) min_price = fields.IntField(required=True) max_price = fields.IntField(required=True) restaurant_types = fields.ListField(field=fields.StringField(), required=True)
class Location(Document): """ This class represents a location in the database """ name = fields.StringField(required=True) city = fields.StringField(required=True) country = fields.StringField(required=True) iata = fields.StringField() icao = fields.StringField() location = fields.GeoPointField() altitude = fields.FloatField() timezone = fields.FloatField() dst = fields.StringField() tz = fields.StringField() meta = {'allow_inheritance': True}
class Foo(Document): string = fields.StringField() required = fields.StringField(required=True) choices = fields.StringField(choices=('foo', 'bar', 'baz')) regex = fields.StringField(regex=r'^[a-z]*$') length = fields.StringField(min_length=1, max_length=3) strings = fields.ListField(fields.StringField()) sorted_strings = fields.SortedListField(fields.StringField()) integer = fields.IntField() bounded_int = fields.IntField(min_value=0, max_value=10) longeger = fields.LongField() bounded_long = fields.LongField(min_value=0, max_value=10) floating = fields.FloatField() bounded_float = fields.FloatField(min_value=0.0, max_value=1.0) boolean = fields.BooleanField() datetime = fields.DateTimeField() complex_datetime = fields.ComplexDateTimeField() binary = fields.BinaryField() bounded_binary = fields.BinaryField(max_bytes=8) mapping = fields.MapField(fields.StringField()) uuid = fields.UUIDField() old_geopoint = fields.GeoPointField() point = fields.PointField() line = fields.LineStringField() polygon = fields.PolygonField() points = fields.MultiPointField() lines = fields.MultiLineStringField() polygons = fields.MultiPolygonField() even_length_string = fields.StringField( validation=lambda s: len(s) % 2 == 0) @fields.EmbeddedDocumentField class embedded_bar(EmbeddedDocument): bar = fields.StringField() @fields.EmbeddedDocumentListField class embedded_baz(EmbeddedDocument): baz = fields.StringField()
class Address(EmbeddedDocument): """An address wrapper which can be embedded in any object.""" TYPES = (("HOME", pgettext_lazy("address type", "Home")), ("WORK", pgettext_lazy("address type", "Work")), ("DELIVERY", pgettext_lazy("address type", "Delivery")), ("BILLING", pgettext_lazy("address type", "Billing")), ("OTHER", pgettext_lazy("address type", "Other"))) label = fields.StringField(max_length=64) type = fields.StringField(choices=TYPES) postoffice_box = fields.StringField(max_length=64) street_address = fields.StringField(required=True, max_length=128) extended_address = fields.StringField(max_length=128) postal_code = fields.StringField(max_length=16) city = fields.StringField(max_length=64) state = fields.StringField(max_length=64) country = fields.StringField(max_length=64) geo_point = fields.GeoPointField() def __eq__(self, other): """Equal comparison should only be based on fields values""" if isinstance(other, Address) and \ self.label == other.label and \ self.type == other.type and \ self.postoffice_box == other.postoffice_box and \ self.street_address == other.street_address and \ self.extended_address == other.extended_address and \ self.postal_code == other.postal_code and \ self.city == other.city and \ self.state == other.state and \ self.country == other.country and \ self.geo_point == other.geo_point: return True else: return False @staticmethod def concat_fields(field1, field2): """ Method used in the :func:`~contacts.models.Address.get_formatted` method to concatenate fields like state and country. """ if not field1 and not field2: return None if field1 and not field2: return field1 if not field1 and field2: return field2 if field1 and field2: return ", ".join([field1, field2]) def get_formatted(self): """ Returns a concatenated list of :class:`~contacts.models.Address` attributes: - Street address - Extended address, post office box - Postal code, City - State, Country """ ret = [ self.street_address, Address.concat_fields(self.extended_address, self.postoffice_box), Address.concat_fields(self.postal_code, self.city), Address.concat_fields(self.state, self.country) ] # Returns only non-blank lines return [line for line in ret if line]
class Log(Document): data = fields.FloatField(required=True) ts = fields.DateTimeField(default=datetime.datetime.now) location = fields.GeoPointField(required=False)
class Address(gj.EmbeddedDocument): country = fields.StringField(required=True, max_length=50) city = fields.StringField(required=True, max_length=50) street = fields.StringField(required=True, max_length=70) coordinates = fields.GeoPointField(required=True)
class Location(EmbeddedDocument): address = fields.StringField() coordinates = fields.GeoPointField()
class Post(Document): meta = { "collection": "posts", } objects = QuerySetManager() @classmethod def dead_posts(cls) -> QuerySet[Post]: return cls.objects().filter(is_hidden=True) _id = fields.StringField(name="_id", primary_key=True) organization = fields.StringField(help_text="org where the post belongs") author = fields.StringField(required=False, help_text="Author of the post") title = fields.StringField() body = fields.StringField(help_text="contents of post") created_at = fields.DateTimeField(default=datetime.datetime.utcnow) kind = fields.StringField(choices=["new", "archive"]) location = fields.StringField(required=False, default="home-page") is_hidden = fields.BooleanField(default=False) spam_id = fields.ObjectIdField(required=False, null=True) spam_flagged = fields.BooleanField(null=True) spam_date = fields.DateTimeField(required=False, null=True) spam_user_id = fields.UUIDField(required=False, null=True) comment_count = fields.IntField(required=False) errors = fields.ListField( field=fields.DictField(field=fields.StringField()), default=[], help_text="some sort of errors", ) results = fields.DictField() attachments = fields.EmbeddedDocumentListField( PostAttachment, required=False, help_text="random attachments") main_attachment = fields.EmbeddedDocumentField( PostAttachment, required=True, help_text="random attachments") tags = fields.MapField( required=False, field=fields.StringField(required=True), help_text=("Map tag names to descriptions"), ) font = fields.EnumField(Font) font_required = fields.EnumField(Font, required=True) font_default = fields.EnumField(Font, default=Font.Helvetica) font_required_default = fields.EnumField(Font, required=True, default=Font.Helvetica) url = fields.URLField() url_required = fields.URLField(required=True) url_default = fields.URLField(default="https://example.org") url_required_default = fields.URLField(required=True, default="https://example.org") url_with_extra_args = fields.URLField(verify_exists=False, url_regex=None, schemas=["ftp://"], regex="bar") geo = fields.GeoPointField() geo_required = fields.GeoPointField(required=True) geo_default = fields.GeoPointField(default=(1, 2)) geo_required_default = fields.GeoPointField(required=True, default=(1, 2)) def set_hidden(self, hidden: bool) -> None: self.hidden = hidden self.save() def get_tag_names(self) -> KeysView[str]: return self.tags.keys()