Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@
option = new Option(newRepr, newId);
select.options.add(option);
// Update SelectBox cache for related fields.
if (window.SelectBox !== undefined && !SelectBox.cache[currentSelect.id]) {
if (
window.SelectBox !== undefined
&& !SelectBox.cache[currentSelect.id]
// Only if SelectBox is managing that field.
&& SelectBox.cache[select.id]
) {
SelectBox.add_to_cache(select.id, option);
// Sort if there are any groups present
if (SelectBox.cache[select.id].some(item => item.group)) {
Expand Down
12 changes: 6 additions & 6 deletions docs/ref/models/querysets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ interested in the exact number of entries, you could do this:
>>> blogs = Blog.objects.alias(entries=Count("entry")).filter(entries__gt=5)

``alias()`` can be used in conjunction with :meth:`annotate`, :meth:`exclude`,
:meth:`filter`, :meth:`order_by`, and :meth:`update`. To use aliased expression
with other methods (e.g. :meth:`aggregate`), you must promote it to an
annotation::
:meth:`filter`, :meth:`order_by`, and :meth:`update`. To use an aliased
expression with other methods (e.g. :meth:`aggregate`), you must promote it to
an annotation::

Blog.objects.alias(entries=Count("entry")).annotate(
entries=F("entries"),
Expand All @@ -341,9 +341,9 @@ annotation::
:meth:`filter` and :meth:`order_by` can take expressions directly, but
expression construction and usage often does not happen in the same place (for
example, ``QuerySet`` method creates expressions, for later use in views).
``alias()`` allows building complex expressions incrementally, possibly
spanning multiple methods and modules, refer to the expression parts by their
aliases and only use :meth:`annotate` for the final result.
``alias()`` allows building complex expressions incrementally (possibly
spanning multiple methods and modules), referring to the expression parts by
their aliases, and only using :meth:`annotate` for the final result.

``order_by()``
~~~~~~~~~~~~~~
Expand Down
4 changes: 4 additions & 0 deletions tests/admin_views/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,3 +1196,7 @@ def __str__(self):
class CamelCaseRelatedModel(models.Model):
m2m = models.ManyToManyField(CamelCaseModel, related_name="m2m")
fk = models.ForeignKey(CamelCaseModel, on_delete=models.CASCADE, related_name="fk")
# Add another relation that will not participate in filter_horizontal.
fk2 = models.ForeignKey(
CamelCaseModel, on_delete=models.CASCADE, related_name="fk2"
)