[Answer]-Django auth manytomanyfield

1👍

Basically userid_id has a manytomanyfield to User, hence you will be creating another table named api_UserFile_userid_id and when you will display in admin list view you will have to pass the entire queryset of User model to select userids and hence you can query accordingly either on pk or username etc depending upon constraints

Hence define UserFile model class as:

class UserFile(models.Model):
    userid_id = models.ManyToManyField(User)
    fileid_id = models.ManyToManyField(FileIndex)
    grant_date = models.DateTimeField()
    revoke_date = models.DateTimeField(blank=True)
    class Meta:
        db_table = 'auth_files'
        verbose_name = 'User File Matrix'
        verbose_name_plural = 'User File Matricies'

    def get_userids(self):
        return "\n".join([u.pk for u in self.user.all()])

    def get_fileids(self):
        return "\n".join([f.pk for f in self.fileindex.all()])

In the admin.py change:

class UserFileAdmin(admin.ModelAdmin):
    # ...
    list_display = ('userid', 'fileid', 'grant_date', 'revoke_date')
    list_filter = ['userid']

To

class UserFileAdmin(admin.ModelAdmin):
    # ...
    list_display = ('get_userids', 'get_fileids', 'grant_date', 'revoke_date')
    list_filter = ['userid_id']

Leave a comment