Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChainedManytoManyField not working with inline forms #336

Open
7 tasks done
raftorres opened this issue Oct 24, 2021 · 0 comments
Open
7 tasks done

ChainedManytoManyField not working with inline forms #336

raftorres opened this issue Oct 24, 2021 · 0 comments

Comments

@raftorres
Copy link

raftorres commented Oct 24, 2021

You MUST use this template when reporting issues. Please make sure you follow the checklist and fill in all of the information sections below.


All versions of django-smart-selects prior to version 1.2.8 are vulnerable to an XSS attack as detailed in issue 171. As a result, all previous versions have been removed from PyPI to prevent users from installing insecure versions. All users are urged to upgrade as soon as possible.

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. Git clone the master to a app directory
  2. Run migrations and load data json
  3. Started test_app and use the portal admin
  4. Try add new membership inside groups

Actual behavior

ChainedManytoManyField not working with inline forms

Expected behavior

Tested with Python 3.8 / Django 3.2 / django-smarts-selects last version 1.5.9

Code in models.py

# Test many to many with inlines and formsets
class Person(models.Model):
    name = models.CharField(max_length=128)

    def __str__(self):
        return "%s" % self.name


class Group(models.Model):
    name = models.CharField(max_length=128)
    members = models.ManyToManyField(Person, through="Membership")

    def __str__(self):
        return "%s" % self.name


class Talent(models.Model):
    name = models.CharField(max_length=64)
    persons = models.ManyToManyField(Person, blank=True)

    def __str__(self):
        return "%s" % self.name


class Membership(models.Model):
    person = models.ForeignKey(Person, on_delete=models.CASCADE)
    group = models.ForeignKey(Group, on_delete=models.CASCADE)
    talents = ChainedManyToManyField(
        Talent, chained_field="person", chained_model_field="persons", horizontal=True
    )
    date_joined = models.DateField()

Code admin.py

class MembershipInline(admin.TabularInline):
    model = Membership
    extra = 1


class PersonAdmin(admin.ModelAdmin):
    list_display = ("name",)


class GroupAdmin(admin.ModelAdmin):
    inlines = (MembershipInline,)


class TalentAdmin(admin.ModelAdmin):
    list_display = ("name",)


When I try to add a new membership, it does not load relationship data within inline forms when selecting person

image

image

ChainedForeingKey works, but ChainedManytoManyField fails. The console and network do not throw any errors.

Please, any solution?

@raftorres raftorres changed the title ManytoManyField not working with inline forms ChainedManytoManyField not working with inline forms Oct 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant