Python mongoengine.fields.BaseField() Examples
The following are 4
code examples of mongoengine.fields.BaseField().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mongoengine.fields
, or try the search function
.
Example #1
Source File: test_filtersets.py From drf-mongo-filters with GNU General Public License v2.0 | 5 votes |
def test_custom_type(self): class FooField(fields.BaseField): pass class MockModel(Document): foo = FooField() class TestFS(ModelFilterset): filters_mapping = { FooField: filters.CharFilter } class Meta: model = MockModel fs = TestFS() self.assertEqual(set(fs.filters.keys()), set(['id', 'foo']))
Example #2
Source File: extras_fields.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def register(self, key, dbtype): '''Register a DB type to add constraint on a given extra key''' if not issubclass(dbtype, (BaseField, EmbeddedDocument)): msg = 'ExtrasField can only register MongoEngine fields' raise TypeError(msg) self.registered[key] = dbtype
Example #3
Source File: test_model.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def test_validate_custom_type(self): class Tester(db.Document): extras = db.ExtrasField() @Tester.extras('test') class Custom(BaseField): def validate(self, value): if not isinstance(value, dict): raise db.ValidationError('Should be a dict instance') tester = Tester(extras={'test': {}}) tester.validate()
Example #4
Source File: repr.py From django-rest-framework-mongoengine with MIT License | 5 votes |
def smart_repr(value): if isinstance(value, QuerySet): return manager_repr(value) if isinstance(value, BaseField): return mongo_field_repr(value) if isinstance(value, BaseDocument): return mongo_field_repr(value) if isinstance(value, Field): return field_repr(value) value = repr(value) # Representations like u'help text' # should simply be presented as 'help text' value = uni_lit_re.sub("'\\1'", value) # Representations like # <django.core.validators.RegexValidator object at 0x1047af050> # Should be presented as # <django.core.validators.RegexValidator object> value = re.sub(' at 0x[0-9a-f]{4,32}>', '>', value) return value