def delete_preferences(queryset):
    """
    Delete preferences objects if they are not present in registry. Return a list of deleted objects
    """
    deleted = []

    # Iterate through preferences. If an error is raised when accessing preference object, just delete it
    for p in queryset:
        try:
            pref = p.preference
        except __HOLE__:
            p.delete()
            deleted.append(p)

    return deleted
dataset/ETHPy150Open EliotBerriot/django-dynamic-preferences/dynamic_preferences/management/commands/checkpreferences.py/delete_preferences