From aed181df87c1e1788e424bf74dea12b6c42338ed Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sat, 11 Jan 2025 20:19:34 -0500 Subject: [PATCH] edits --- .pre-commit-config.yaml | 2 +- .../fields/embedded_model.py | 2 +- .../forms/fields/embedded_model.py | 4 ++-- docs/source/fields.rst | 3 ++- docs/source/forms.rst | 18 ++++++++++++++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 782c31ca..60ea59c6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -44,7 +44,7 @@ repos: hooks: - id: rstcheck additional_dependencies: [sphinx] - args: ["--ignore-directives=fieldlookup", "--ignore-roles=djadmin,lookup,setting"] + args: ["--ignore-directives=django-admin,fieldlookup,setting", "--ignore-roles=djadmin,lookup,setting"] # We use the Python version instead of the original version which seems to require Docker # https://github.com/koalaman/shellcheck-precommit diff --git a/django_mongodb_backend/fields/embedded_model.py b/django_mongodb_backend/fields/embedded_model.py index 18840355..2dcbfdd8 100644 --- a/django_mongodb_backend/fields/embedded_model.py +++ b/django_mongodb_backend/fields/embedded_model.py @@ -135,7 +135,7 @@ def formfield(self, **kwargs): **{ "form_class": forms.EmbeddedModelField, "model": self.embedded_model, - "name": self.name, + "prefix": self.name, **kwargs, } ) diff --git a/django_mongodb_backend/forms/fields/embedded_model.py b/django_mongodb_backend/forms/fields/embedded_model.py index 89f9b5e1..2481b7f1 100644 --- a/django_mongodb_backend/forms/fields/embedded_model.py +++ b/django_mongodb_backend/forms/fields/embedded_model.py @@ -32,10 +32,10 @@ class EmbeddedModelField(forms.MultiValueField): "incomplete": _("Enter all required values."), } - def __init__(self, model, name, *args, **kwargs): + def __init__(self, model, prefix, *args, **kwargs): form_kwargs = {} # The field must be prefixed with the name of the field. - form_kwargs["prefix"] = name + form_kwargs["prefix"] = prefix self.form_kwargs = form_kwargs self.model_form_cls = modelform_factory(model, fields="__all__") self.model_form = self.model_form_cls(**form_kwargs) diff --git a/docs/source/fields.rst b/docs/source/fields.rst index 99fe3599..270ea7d7 100644 --- a/docs/source/fields.rst +++ b/docs/source/fields.rst @@ -36,7 +36,8 @@ Some MongoDB-specific fields are available in ``django_mongodb_backend.fields``. :class:`~django.db.models.OneToOneField` and :class:`~django.db.models.ManyToManyField`) and file fields ( :class:`~django.db.models.FileField` and - :class:`~django.db.models.ImageField`). + :class:`~django.db.models.ImageField`). :class:`EmbeddedModelField` is + also not (yet) supported. It is possible to nest array fields - you can specify an instance of ``ArrayField`` as the ``base_field``. For example:: diff --git a/docs/source/forms.rst b/docs/source/forms.rst index eb020073..64c42755 100644 --- a/docs/source/forms.rst +++ b/docs/source/forms.rst @@ -5,6 +5,24 @@ Forms API reference Some MongoDB-specific fields are available in ``django_mongodb_backend.forms``. +``EmbeddedModelField`` +---------------------- + +.. class:: EmbeddedModelField(model, prefix, **kwargs) + + A field which maps to a model. The field will render as a + :class:`~django.forms.ModelForm`. + + .. attribute:: model + + This is a required argument that specifies the model class. + + .. attribute:: prefix + + This is a required argument that specifies the prefix that all fields + in this field's subform will have so that the names don't collide with + fields in the main form. + ``ObjectIdField`` -----------------