Monday, November 29, 2021

Issue in rendering of Inline forms on Django Admin site

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.



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

--
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+unsubscribe@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.

No comments:

Post a Comment