class MyAdmin(admin.ModelAdmin):

    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name in ('foo', 'bar'):
            pass
How to show raw_id value of a ManyToMany relation in the Django admin?