def delete_preferences(queryset):
    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 KeyError:
            p.delete()
            deleted.append(p)

    return deleted
Delete preferences objects if they are not present in registry. Return a list of deleted objects
dataset/ETHPy150Open EliotBerriot/django-dynamic-preferences/dynamic_preferences/management/commands/checkpreferences.py/delete_preferences