Cannot remove new row in TabularInline when using autocomplete_fields

84 views
Skip to first unread message

Germain Lem

unread,
Mar 2, 2019, 5:53:47 PM3/2/19
to Django users
This is my first post and contribution. I hope I do it correctly.

I dont know if it is a bug or a needed feature but here is the problem.

I use autocomplete_fields on a field in an admin.TabularInline, the field concerned is mandatory.

When you choose a value with the autocomplete you cannot put back a blank value. 
This behavior is normal in standard admin view because the field is mandatory (null=False and blank=False). 
But in the case of validating a new row in a Inline admin form you are stuck. (see attached image)


They are two workaroud:

First refresh the page but you loose all the other modifications.

The second put blank=True on the ForeignKey, this allow to put the field blank by showingup a cross next to the field. But now you can put blank on existing value and in standard admin view, then you will potentialy get the RelatedObjectDoesNotExist exception. 

I see three solutions
Copy the behavior of the standard select: even if blank=False, you can put a blank value on inline fields.
Allow blank value only for new row when blank=False
Or (dirty) showing up the delete checkbox for new row. If a new form in a formset as the Delete value true, just ignore it.


djangoautocompletebug.JPG
Reply all
Reply to author
Forward
0 new messages