Issue in rendering of Inline forms on Django Admin site

65 views
Skip to first unread message

Andrea Arighi

unread,
Nov 29, 2021, 6:28:33 PM11/29/21
to django...@googlegroups.com
Good evening,
I am encountering a weird bug when rendering Inline forms on the "Add" view of a ModelAdmin.

Here is a minimum example with Django version 2.2.4

- - - - - - -

in models.py:

class MyModel(models.Model):
text = models.CharField(max_length=100)

class RelatedModel(models.Model):
parent = models.ForeignKey(MyModel, null=False, on_delete=models.CASCADE)
number = models.DecimalField(decimal_places=2, max_digits=10, null=False, blank=False)

in admin.py:
class RelatedModelInlineTabular(admin.TabularInline):
model = RelatedModel
show_change_link = False
fields = ("number", )

class TestMyModelCreate(admin.ModelAdmin):
fields = ['text', ]
inlines = [RelatedModelInlineTabular]

admin.site.register(MyModel, TestMyModelCreate)

Steps to replicate:
  • Login to django admin website
  • open the "add" view for MyModel (i.e. navigate to the list of Models and click on the "Add new" button

Expected result:
The form displays an empty text field. Below that, an Inline form is displayed with 3 empty rows for potential related instances of RelatedModel

Actual result:
The Inline form is displayed twice, each instance with its own 3 empty rows, as if I had specified it twice.

- - - - - -
I attach screenshots of the actual page ( Discount is the related Model). Please note that I get the same result with both StackedInline and TabularInline.

immagine.png

Am I making some trivial error here that could explain what's happening? Or is this is a known bug? Thank you in advance to anyone that will help.

Best regards
*  *  *  *  *
Andrea Arighi ~ Software Developer
Please consider the environment before printing this email

Gabo LaTo

unread,
Dec 1, 2021, 5:07:01 PM12/1/21
to django...@googlegroups.com
Aren't you missing the model class attribute in TestMyModelCreate?

Like this:
class TestMyModelCreate(admin.ModelAdmin):
model = MyModel

fields = ['text', ]
inlines = [RelatedModelInlineTabular]
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJzUX%3D68ejwz2Q0Lwvarw-hA%3DV5xsKfL%3D%2BHrsLzuHDkF2_ApmA%40mail.gmail.com.

Gabo LaTo

unread,
Dec 1, 2021, 5:09:17 PM12/1/21
to django...@googlegroups.com
Nope, sorry I missread
Reply all
Reply to author
Forward
0 new messages