Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Jan 12, 2025
1 parent dbd3de7 commit aed181d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion django_mongodb_backend/fields/embedded_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def formfield(self, **kwargs):
**{
"form_class": forms.EmbeddedModelField,
"model": self.embedded_model,
"name": self.name,
"prefix": self.name,
**kwargs,
}
)
Expand Down
4 changes: 2 additions & 2 deletions django_mongodb_backend/forms/fields/embedded_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion docs/source/fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
18 changes: 18 additions & 0 deletions docs/source/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
-----------------

Expand Down

0 comments on commit aed181d

Please sign in to comment.