question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't work on a Inline Admin Page

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
manelcloscommented, Apr 20, 2021

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

0reactions
manelcloscommented, Apr 25, 2022

AFAIK, integer Primary Keys are still required

Read more comments on GitHub >

github_iconTop Results From Across the Web

django admin form does not work in inline - Stack Overflow
Show activity on this post. I didn't test, but this should do it class LoginInline(admin.StackedInline): form = LoginForm model = Login.
Read more >
Problems specifying fields for admin inline - Google Groups
I'm trying to modify the default Site admin page to include an inline model. Everything seems to be working fine except that no...
Read more >
Writing your first Django app, part 2
Django solves the problem of creating a unified interface for site administrators to ... First we'll need to create a user who can...
Read more >
Django admin dynamic Inline positioning - Habr
My gut feeling told me, there were another way around that problem. The first solution I found was from 2017. It had too...
Read more >
Unable to Edit Records via Inline Editing in a List View
Other considerations and troubleshooting. Common Issues preventing inline editing: A field must be present on at least one-page layout, and the same page...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found