Allow only editing the current selected Foreign Key in Django Admin
<p>So currently I have something like this:</p>

<p>Model:</p>

<pre><code>class ConfirmEmail(models.Model): 
     report = models.ForeignKey(Report)
     owner = models.CharField(max_length = 100)
     emails = models.ManyToManyField(Sdm)
</code></pre>

<p>Admin:    </p>

<pre><code>@admin.register(ConfirmEmail)
class ConfirmEmailAdmin(admin.ModelAdmin):
    change_form_template = 'admin/phone/index.html'
    readonly_fields = ('owner',)
    filter_horizontal = ('emails',)
    list_display = ('owner','report')
</code></pre>

<p>I create these objects in code - meaning I set the report object.  But what I would like in the <code>Django admin</code> is if I could allow a user to edit that report object but only the one set.  They would be allowed to change it (so hopefully the drop down menu would no longer be there) so the nice pencil icon would still be there, but things like that "+" icon would be gone.</p>

<p>And this is not to say the user can't edit all reports, it's just that in the <code>ConfirmEmail Admin</code> they can only view that specific report attached to it.</p>

<p>I've been smacking away at this and can't seem to get it work. </p>

<p>I would also be inclined to just have the current Report Form embedded into the <code>ConfirmEmail</code> form - but don't know how I would go about doing that.</p>

<p>You should first introduce a model admin for your Report model, then override the <strong>has_add_permission</strong> function of your ReportAdmin.</p>

<pre><code>@admin.register(Report)
class ReportAdmin(admin.ModelAdmin):  

    # whatever you want here

    def has_add_permission(self, request):
        return False
</code></pre>

<p>You can also remove/disable the + button <strong>using javascript</strong> in the page, but be aware that the user can cause damage if he knows the add url, or disables javascript.</p>

python django django-admin