Created
March 9, 2016 14:01
-
-
Save jpic/b93ee62a3060dc408b0e to your computer and use it in GitHub Desktop.
Demonstrate what this change in Django would allow users to do: https://github.com/jpic/django/commit/d102f362f3c1ceaf2d5224d71f788c0821a481ae Read the full article here: http://blog.yourlabs.org/post/140742987608/porting-modelform-enhancements-from
This file contains 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 TestApp(AppConfig): | |
name = 'select2_one_to_one' | |
def ready(self): | |
model = self.get_model('TestModel') | |
# Perhaps that's the kind of nice place to override this kind of things | |
model._meta.get_field('test').formfield_defaults['widget'] = forms.RadioSelect | |
# django-autocomplete-light users would execute something like: | |
model._meta.get_field('test').formfield_defaults['widget'] = autocomplete.Select2(url='my_autocomplete_url') |
This file contains 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 TestModel(models.Model): | |
name = models.CharField(max_length=200) | |
test = models.OneToOneField( | |
'self', | |
null=True, | |
blank=True, | |
related_name='related_test_models', | |
# This seems like it would always be useful | |
formfield_defaults={ | |
'widget': forms.RadioSelect | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment