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

Unable to delete inline when it has the same formset prefix as another inline in the same admin #60

Closed
macr opened this issue Oct 7, 2016 · 7 comments

Comments

@macr
Copy link

macr commented Oct 7, 2016

I'm still having similar issue reported on #26 when using related_name AND proxy model on admin to use the same model more than once. The moment I use a related_name, no matter what value I use, the checkbox to delete can't be checked anymore

@fdintino
Copy link
Member

fdintino commented Oct 7, 2016

Could you post the code for your models and admin so that I can try to reproduce the bug? (Or at least as much code as is needed to see the bug). What version of Django are you using? With or without grappelli?

@macr
Copy link
Author

macr commented Oct 7, 2016

#admin.py
class Aa(Bar):
    class Meta:
        proxy=True

class Bb(Bar):
    class Meta:
        proxy=True

class AaModelForm(ModelForm):
    class Meta:
        model = Bar
        exclude = []

class BbModelForm(ModelForm):
    class Meta:
        model = Bar
        exclude = []

class AaAdminInline(nested_admin.NestedStackedInline):
    model = Aa
    form = AaModelForm
    extra = 1
class BbAdminInline(nested_admin.NestedStackedInline):
    model = Bb
    form = BbModelForm
    extra = 1

class FooAdmin(nested_admin.NestedModelAdmin):
    inlines = [AaAdminInline, BbAdminInline]

admin.site.register(Foo, FooAdmin)
#models.py
class Foo(models.Model):
    foo_field1 = models.CharField(max_length=10,blank=True, null=True)
    foo_field2 = models.CharField(max_length=10,blank=True, null=True)


class Bar(models.Model):
    foo = models.ForeignKey(Foo, related_name='bar_foo')
    bar_field1 = models.CharField(max_length=10,blank=True, null=True)
    bar_field2 = models.CharField(max_length=10,blank=True, null=True)

This should be enough to reproduce it. No grappell. Django 1.10

I'm using custom get_queryset on the inlines so they are not just the same objects repeated. It works fine on standard Django admin or when I remove the related_name

@fdintino fdintino changed the title Deleting child not working Unable to delete inline when it has the same formset prefix as another inline in the same admin Oct 12, 2016
@fdintino
Copy link
Member

fdintino commented Oct 12, 2016

Thanks for the report! It turns out that the proxy models are somewhat incidental to the underlying issue: the same bug surfaces if you have two inline classes on an admin that point to the same model. The problem occurs when multiple inline admin formsets on a parent model share the same prefix, which is why you are seeing it when you specify a related_name (if it wasn't explicitly specified, the related_name for the reverse relationship—which is what the formset prefix is based on—is different for the two inlines, aa_set and bb_set). By specifying the related_name you are forcing Django to use the concrete model, since there would only be bar_foo, and that only points to the concrete model; this is also why you need to override get_queryset() on the inline (without the related_name you could instead just use a custom model manager to have different querysets for the proxy models).

I'm a bit surprised no one has ever encountered this issue before, but it should be enough to tweak the regular expressions that parse the form prefixes. I'll take a look.

@fdintino
Copy link
Member

This was fixed in the 3.0.11 release of django-nested-admin. Let me know if you have any more issues.

@grigi
Copy link

grigi commented Nov 2, 2016

Hi, Since the 3.0.11 release, I now have this problem, whereas I didn't have it before. I also have a new problem where dragging a nested form to change the order is now broken (I'm not using grappeli).

I am not using proxy models at all.

Also, nothing in the browser logs for the checkboxes, but for dragging to change order I get a "t is undefined".

@fdintino
Copy link
Member

fdintino commented Nov 3, 2016

@grigi Could it be that your browser is loading cached versions of the nested admin static files? That's my best guess. If that is the case, I recommend setting STATICFILES_STORAGE to either ManifestStaticFilesStorage or CachedStaticFilesStorage to make sure static files get cache-busted in the future.

If that is not the issue, set NESTED_ADMIN_DEBUG = True in your settings file and paste the unminified stack trace of your browser error.

@grigi
Copy link

grigi commented Nov 3, 2016

Nope, tested that the browser was running non cached versions. I'll try the NESTED_ADMIN_DEBUG = True option for the dragging. (although there was no exception at all in the js for the delete checkbox issue.

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

3 participants