Django ModelAdmin join two models using QuerySet for view both columns

In my django application i have two models:

class Results(models.Model):
    device = models.ForeignKey(Device, null=True, on_delete=models.SET_NULL)
    proj_code = models.CharField(max_length=400)
    res_key = models.SlugField(max_length=80, verbose_name="Message unique key", primary_key=True, unique=True)
    read_date = models.DateTimeField(verbose_name="Datetime of vals readings")
    unit = models.ForeignKey(ModbusDevice, null=True, on_delete=models.SET_NULL)

and

class VarsResults(models.Model):
    id = models.AutoField(primary_key=True)
    key_res = models.ForeignKey(Results, related_name="keyres", on_delete=models.CASCADE)
    var_id = models.ForeignKey(ModbusVariable, null=True, on_delete=models.SET_NULL)
    var_val = models.CharField(max_length=400, blank=True)
    var_val_conv = models.CharField(max_length=100, blank=True, null=True)
    base_byte_order = models.CharField(max_length=15)
    var_hash = models.CharField(max_length=400)
    has_error = models.BooleanField(default=False)

Well i would in my admin.py create a ModelAdmin that can use both fields from two models in view:

@admin.register(Results)
class ModbusAdmin(admin.ModelAdmin):

    list_display = ('res_key', 'proj_code', 'read_date', 'unit' ...HERE I WOULD ALSO MY VarsResults MODEL FIELDS)
    list_filter = ('proj_code', 'unit')
    search_fields = ('proj_code', )
    ordering = ('-read_date', 'proj_code')

    list_display_links = None

    readonly_fields = ()

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False

    def save_model(self, request, obj, form, change):
        pass

    def delete_model(self, request, obj):
        pass

    def save_related(self, request, form, formsets, change):
        pass

How can i use for example a queryset from my two models instead a single model in my ModelAdmin for use both fields?

So many thanks in advance

Back to Top