django-smart-selects: Doesn't work on a Inline Admin Page

Checklist

Put an x in the bracket when you have completed each task, like this: [x]

  • This issue is not about installing previous versions of django-smart-selects older than 1.2.8. I understand that previous versions are insecure and will not receive any support whatsoever.
  • I have verified that that issue exists against the master branch of django-smart-selects.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • I have debugged the issue to the smart_selects app.
  • I have reduced the issue to the simplest possible case.
  • I have included all relevant sections of models.py, forms.py, and views.py with problems.
  • I have used GitHub Flavored Markdown to style all of my posted code.

Steps to reproduce

  1. Use Django Smart Selects on a Inline Admin Page.

Actual behavior

I use Django Smart Selects to dynamically choose a document based on its document type. It work fine on an Admin Page, but I have another Page with an Inline Admin and there I’ve got this error:

?_changelist_filters=o%3D5.2.3%26p%3D2:1 Uncaught SyntaxError: Unexpected number in JSON at position 1
    at JSON.parse (<anonymous>)
    at initItem (bindfields.js:8)
    at HTMLSelectElement.<anonymous> (bindfields.js:25)
    at Function.each (jquery.min.js:2)
    at HTMLDocument.<anonymous> (bindfields.js:24)
    at i (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at Function.ready (jquery.min.js:2)
    at HTMLDocument.J (jquery.min.js:2)
initItem @ bindfields.js:8
(anonymous) @ bindfields.js:25
each @ jquery.min.js:2
(anonymous) @ bindfields.js:24
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
J @ jquery.min.js:2

MyClass model:

class MyClass(BaseModel):
idcliente = models.IntegerField(default=102, editable=False)
(...)
idtipodoc = models.ForeignKey('Tipodoccliente', db_column='idtipodoc', related_name='+')
nrdoc = ChainedForeignKey(
    Cliente, 
    chained_field="idtipodoc",
    chained_model_field="idtipodoc", 
    show_all=False, 
    auto_choose=True,
    db_column='nrdoc', related_name='+'
)
class Cliente(BaseModel):
idtipodoc = models.ForeignKey('Tipodoccliente', db_column='idtipodoc', verbose_name='Tipo do Documento', related_name='+')
nrdoc = models.CharField(primary_key=True, unique=True, max_length=15, verbose_name='Numero do Documento', validators=[numeric])
nome = models.CharField(max_length=100, verbose_name='Nome')
(...)

MyClass admin inline:

class MyClasslInline(admin.TabularInline):
model = MyClass
fields = ['idcliente', (...), 'nrdoc']
max_num = 1

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 1
  • Comments: 15 (6 by maintainers)

Most upvoted comments

@Asocia after looking at the html you pasted and noticed that you are not using integers for your Primary Keys, which is currently unsupported by smart-selects.