def _diff_queryset(reference, qs1, qs2):
    """Compares two QuerySets by their primary keys."""
    if qs1 and qs2:
        pks1 = qs1.values_list('pk', flat=True)
        pks2 = qs2.values_list('pk', flat=True)
        if set(pks1) != set(pks2):
            return qs2
    elif qs1:
        if qs1.count():
            return qs2
    elif qs2:
        if qs2.count():
            return qs2
