Djongo is a Django and MongoDB database connector witch brings, beside others, the ArrayField to Django Models. It allows one to store multiple instances of an other djongo.models.Model
in an unique MongoDB Array field inside a document related with the Model
that has the Arrayfield
As described in source documentation: "The model of the container must be declared as abstract, thus should not be treated as a collection of its own."
As well as in djongo's site tutorials
"In case you don’t plan on using your embedded model as a standalone model (which means it will always be embedded inside a parent model) you should add the class Meta
and abstract = True
This way Djongo will never register this model as an actual model."
This way I made:
# models.py
class Contact(models.Model):
key = models.CharField(max_length=100)
class Meta:
abstract = True
class ContactForm(forms.ModelForm):
class Meta:
model = Contact
fields = ('key',)
class Person(models.Model):
_id = models.ObjectIdField()
...
contact = models.ArrayField(
model_container=Contact,
model_form_class=ContactForm,
)
objects = models.DjongoManager()
# admin.py
admin.site.register(Person)
$ pip freeze
Django==3.2.4
djongo==1.3.6
pymongo==3.11.4
...
However when I try to add a Person
through Django Admin (in /admin/<app>/person/add/) I receive the error Abstract models cannot be instantiated from .../django/db/models/base.py
This seems inconsistent with Djongo's description. Am I doing something wrong?