[Answer]-Avoid Foreigkey repeat in django admin

1👍

You’d probably need to redefine the models and relations – maybe using some other relation type. So you can add something like that in your admin model(isn’t it admin.ModelAdmin?):

class UserAddressAdmin(admin.ModelAdmin):

    def user_areas(self, obj):
        areas = Area.objects.filter(pk__in=UserAddress.objects.filter(user=obj.user).values("area__id"))
        return "<a href='%s'>%s</a>" % (
            reverse("reverse_to_areas"), obj.user.username)
    user_link.allow_tags = True

    list_display = ['user_areas','area']
👤Tisho

Leave a comment