Django Admin to manage Foreign Key associations on one page

PAGE can be shown on multiple BLOGS.
ACCOUNT can see BLOG PAGE if he/she has PERMISSION on that PAGE for that BLOG.
Here are the models - I think models/DB organization is correct this way:

class Account(models.Model):
    user = models.OneToOneField(User,on_delete=models.CASCADE,)

class Page(RulesModel):
    name = models.CharField(max_length=250)

class Blog(models.Model):
    pages = models.ManyToManyField(Page, through='BlogPage')

class BlogPage(models.Model):
    blog = models.ForeignKey(Blog, on_delete=models.CASCADE)
    page = models.ForeignKey(Page, on_delete=models.CASCADE)
    viewable_by = models.ManyToManyField(Account, through='BlogPagePermission')

class BlogPagePermission(models.Model):
    blog_page = models.ForeignKey(BlogPage, on_delete=models.CASCADE)
    account = models.ForeignKey(Account, on_delete=models.CASCADE)

Now when assigning BLOG PAGE PERMISSIONS to ACCOUNTS, I would like to have this scenario:
1. You open edit page for specific Account
2. You see a list of all PAGES for each BLOG
3. then you mark which PAGES of each BLOG can be viewed.

The problem is I don’t see a way how to achieve this (or similar) by using Django Admin ?

For now I have this:

class BlogPagePermissionInline(admin.TabularInline):
    model = BlogPagePermission
    extra = 0
    show_change_link = False
    fields = ['blog_page',]

class AccountAdmin(admin.ModelAdmin):
    inlines = [BlogPagePermissionInline,]

This way when I open Account admin page, I can add BlogPagePermission and via select widget I can choose one.

But that is not efficient way.

If you’re finding that the admin isn’t doing what you want or is making your life difficult, I’d recommend building out a custom view, then wrapping it in a permissions check for a super user or the correct staff permissions. That way it will do exactly what you want and be as efficient as possible.

Yeah, it seems this will be the only way out :slight_smile: