doableware / djongo

Django and MongoDB database connector
https://www.djongomapper.com
GNU Affero General Public License v3.0
1.86k stars 351 forks source link

Implemented FieldsArrayField in models #663

Open NMagpie opened 1 year ago

NMagpie commented 1 year ago

The FieldsArrayField is a custom Django model field that allows you to create an array of fields inside a document. You can specify a base field when you create an instance of FieldsArrayField, and then use the resulting field like a regular Python list.

class Foo(models.Model):
    tags = FieldsArrayField(models.CharField(max_length=255), blank=True)

We can instanciate such model just using python list:

foo = Foo(
    tags=[ 'foo', 'bar', 'test' ]
)
p-matt commented 9 months ago

Not working as expected

from djongo import models
from geocoding_api.API.mixins import TimestampMixin

class Geocoding(TimestampMixin):
    searchAddresses = models.fields.FieldsArrayField(models.CharField(max_length=255))

Which give

ValueError('You must specify a base_field')