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

"Add Another <Model>' links not being generated, showing only 'javascript://' links #163

Closed
euanmacinnes opened this issue Feb 18, 2020 · 7 comments

Comments

@euanmacinnes
Copy link

euanmacinnes commented Feb 18, 2020

Hi,
I'm using the django admin behind a reverse proxy, which uses the URL sub-folder path /pipeline/ to go to the individual Django apps and admin (which is in /pipeline/admin'),

so I've set up the rules as follows:

urlpatterns = [
path('pipeline/rules/', include('rules.urls')),
path('pipeline/materials/', include('materials.urls')),
path('pipeline/admin/', admin.site.urls),
path('pipeline/nested_admin/', include('nested_admin.urls')),
]

EDIT:
I also tried this with:

urlpatterns = [
path('pipeline/rules/', include('rules.urls')),
path('pipeline/materials/', include('materials.urls')),
path('pipeline/admin/', admin.site.urls),
url(r'^nested_admin/', include('nested_admin.urls')),
]

To no avail.

The nested inlines all appear in Django admin, and Saving the data all work fine, but the links to 'Add Another ' all just show 'javascript://' in the URL in the browser, rather than the expected URLs.

This has to go through a subfolder for many security reasons and multi-homed applications etc.. so I've no option to change this to a port or a different main address.

Any help given is greatly appreciated.

@fdintino
Copy link
Member

The 'Add Another' button isn't a link—it doesn't take you to a different page—it triggers a registered click handler in javascript that adds a new inline. The fact that the link says javascript:// in the browser shouldn't cause any issues with whatever admin urls you're using.

@euanmacinnes
Copy link
Author

euanmacinnes commented Feb 29, 2020 via email

@fdintino
Copy link
Member

Are there any errors in the Web Developer console?

@selected-pixel-jameson
Copy link

selected-pixel-jameson commented Mar 13, 2020

I'm seeing the same issue. No there are no errors in the console. Running Django 2.1.

This is the javascript showing up in the head tag.

Screen Shot 2020-03-13 at 2 22 19 PM

Actually looking at this closer it doesn't appear to be working at all. It is just loading the first inline and not the nested inline.

Inlines

class DashboardContentInline(nested_admin.NestedStackedInline):
    model = DashboardContent

class DashboardItemInline(nested_admin.NestedStackedInline):
    model = DashboardItem
    inline = [DashboardContentInline]

Models

class DashboardSection(models.Model):
    class Meta:
        verbose_name = "Dashboard Section"
        verbose_name_plural = "Dashboard Sections"

    title = models.CharField(max_length=20)
    weight = models.IntegerField(default=0, blank=False, null=False)
    created_at = models.DateTimeField(
        auto_now_add=True, null=False, blank=False)
    updated_at = models.DateTimeField(auto_now=True, null=False, blank=False)
    style = models.CharField(max_length=64, choices=DASHBOARD_STYLES, blank=False, null=False)

class DashboardItem(models.Model):
    section = models.ForeignKey('DashboardSection', on_delete=models.CASCADE)
    title = models.CharField(max_length=20)
    subtitle = models.CharField(max_length=40, blank=True, null=True)
    image = models.CharField(max_length=500, blank=True, null=True)
    icon = models.CharField(max_length=500, blank=True, null=True)
    color_tint = ColorField(verbose_name='Color Tint', blank=True, null=True)
    weight = models.IntegerField(default=0, blank=False, null=False)

class DashboardContent(models.Model):
    content_type = models.CharField(max_length=32, choices=CONTENT_TYPES, blank=True, null=True)
    content_id = models.IntegerField(blank=True, null=True)
    show_all_content = models.BooleanField(default=False, verbose_name='Show All Content', help_text='Checking this box will display a list of all of the specified content type. (i.e. All Issues )')
    show_all_order_by = models.CharField(max_length=32,choices=ORDER_BY,blank=True, null=True, help_text='This choice will define the order the specified content type shows up in when "Show All Content" is checked. (i.e. Recently Added Issues )')
    item = models.ForeignKey('DashboardItem', on_delete=models.CASCADE)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

Admin


class DashboardSectionAdmin(admin.ModelAdmin):
    list_display = ('title',)
    inlines = [DashboardItemInline]

I have run collectstatic and verified that the nested_admin javascript folder exists within the static folder.

It does not appear as if any of the js or css files are being loaded at all.

@selected-pixel-jameson
Copy link

@euanmacinnes Are you by chance storing files to S3 and / or using the ManifestFilesMixin or S3Boto3Storage?

@fdintino
Copy link
Member

@selected-pixel-jameson I see the issue. You need your admin class to extend nested_admin.NestedModelAdmin, not admin.ModelAdmin. I suspect that if you change that, it will work.

@euanmacinnes
Copy link
Author

The problem in the end was the Static files, as they didn't get installed into the published location that went through the reverse proxy. A quick file copy over later got it working again.

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