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
5 changes: 3 additions & 2 deletions src/polymorphic/admin/parentadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from django.template.response import TemplateResponse
from django.urls import URLResolver
from django.utils.encoding import force_str
from django.utils.http import urlencode
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -199,9 +198,11 @@ def add_view(self, request, form_url="", extra_context=None):
else:
real_admin = self._get_real_admin_by_ct(ct_id)
# rebuild form_url, otherwise libraries below will override it.
# Preserve popup-related parameters to ensure popup functionality works
# correctly even after validation errors (issue #612)
form_url = add_preserved_filters(
{
"preserved_filters": urlencode({"ct_id": ct_id}),
"preserved_filters": request.GET.urlencode(),
"opts": self.model._meta,
},
form_url,
Expand Down
6 changes: 6 additions & 0 deletions src/polymorphic/tests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
InlineModelB,
InlineParent,
NoChildren,
ModelWithPolyFK,
)


Expand Down Expand Up @@ -73,3 +74,8 @@ class InlineParentAdmin(PolymorphicInlineSupportMixin, ModelAdmin):
@register(NoChildren)
class NoChildrenAdmin(PolymorphicParentModelAdmin):
child_models = (NoChildren,)


@register(ModelWithPolyFK)
class ModelWithPolyFKAdmin(ModelAdmin):
fields = ["name", "poly_fk"]
4 changes: 2 additions & 2 deletions src/polymorphic/tests/deletion/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2 on 2026-01-06 17:46
# Generated by Django 4.2 on 2026-01-06 23:40

from decimal import Decimal
from django.conf import settings
Expand All @@ -12,8 +12,8 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('contenttypes', '0002_remove_content_type_name'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
Expand Down
13 changes: 11 additions & 2 deletions src/polymorphic/tests/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2 on 2026-01-06 17:46
# Generated by Django 4.2 on 2026-01-06 23:40

from django.conf import settings
from django.db import migrations, models
Expand All @@ -14,8 +14,8 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('auth', '0012_alter_user_first_name_max_length'),
('contenttypes', '0002_remove_content_type_name'),
]

operations = [
Expand Down Expand Up @@ -1075,6 +1075,14 @@ class Migration(migrations.Migration):
'base_manager_name': 'objects',
},
),
migrations.CreateModel(
name='ModelWithPolyFK',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('poly_fk', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='tests.model2a')),
],
),
migrations.CreateModel(
name='ModelUnderRelParent',
fields=[
Expand Down Expand Up @@ -1558,6 +1566,7 @@ class Migration(migrations.Migration):
fields=[
('inlinemodela_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='tests.inlinemodela')),
('field2', models.CharField(max_length=30)),
('file_upload', models.FileField(blank=True, default=None, null=True, upload_to='test_uploads/')),
('plain_a', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='inline_bs', to='tests.plaina')),
],
options={
Expand Down
10 changes: 10 additions & 0 deletions src/polymorphic/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ class InlineModelB(InlineModelA):
related_name="inline_bs",
)

# File field for testing multipart encoding in polymorphic inlines (issue #380)
file_upload = models.FileField(upload_to="test_uploads/", null=True, blank=True, default=None)


class AbstractProject(PolymorphicModel):
topic = models.CharField(max_length=30)
Expand Down Expand Up @@ -730,6 +733,13 @@ class NoChildren(PolymorphicModel):
field1 = models.CharField(max_length=12)


class ModelWithPolyFK(models.Model):
"""Model with FK to polymorphic model for popup testing."""

name = models.CharField(max_length=100)
poly_fk = models.ForeignKey(Model2A, on_delete=models.CASCADE, null=True, blank=True)


class NormalBase(models.Model):
nb_field = models.IntegerField()

Expand Down
Loading
Loading