Created
May 11, 2012 13:19
-
-
Save mattdeboard/2659561 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BaseModelAdmin(object): | |
| #...snip... | |
| def formfield_for_manytomany(self, db_field, request=None, **kwargs): | |
| """ | |
| Get a form Field for a ManyToManyField. | |
| """ | |
| # If it uses an intermediary model that isn't auto created, don't show | |
| # a field in admin. | |
| if not db_field.rel.through._meta.auto_created: | |
| return None | |
| db = kwargs.get('using') | |
| if db_field.name in self.raw_id_fields: | |
| kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.rel, using=db) | |
| kwargs['help_text'] = '' | |
| elif db_field.name in (list(self.filter_vertical) + list(self.filter_horizontal)): | |
| kwargs['widget'] = widgets.FilteredSelectMultiple(db_field.verbose_name, (db_field.name in self.filter_vertical)) | |
| return db_field.formfield(**kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment