I've only skimmed the original thread so idk if the following was suggested
there. What I'd suggest for your project for the first condition is:

1. Subclass the model field you want to change and make it default to
having widget=RadioSelect:

class RadioSelectForeignKey(ForeignKey):
    def formfield(self, **kwargs):
        kwargs.setdefault('widget', RadioSelect)
        return super().formfield(**kwargs)

2. Use RadioSelectForeignKey on all the models that have a FK pointing to
Foo

3. Add a system check <https://docs.djangoproject.com/en/1.10/ref/checks/>
to your project that errors if a FK is added pointing to Foo that isn't a
RadioSelectForeignKey (scan all fields on all models, if they're FK's and
point to Foo, check their class with isinstance)

And similar for your Bar html fields. This one can be done with a check()
method on the model itself.

On 22 December 2016 at 13:05, James Pic <james...@gmail.com> wrote:

> Wow, nice memory Tim !
>
> Yes it's a problem I've been trying to find a solution for during the last
> years. We've had a solution in DAL v2 by providing a custom model form
> which would make relation fields to a model that has an autocomplete
> registered use an autocomplete field by default. This solution was really
> hard to maintain, and not even portable.
>
> I couldn't reuse the system to just FlatPage use a wysiwyg field by
> default, and had to go the usual, and I recon a bit messy road:
> https://gist.github.com/Kub-AT/3676137 This is when I realized it had to
> be part of the features that should be dropped from DAL v2 to v3, in favor
> of a more generic and supported way.
>
> The older discussion proposed another angle, in the spirit of #22609 [0],
> that was not convincing because it would increase coupling between forms
> and models because it requires to add even more form stuff in models,
> because of the nature of the solution that was per-modelfield.
>
> This is why this new proposal is based on a project-level callback setting
> instead:
>
> - does not require to add any additional form stuff to models.py,
> - allows to override default form fields or form field options without
> touching their code.
>
> Note that there was also a suggestion to do something with
> fields_for_model [1] to solve the problem, I don't think we're done
> studying this road on the other thread so there might be more
> implementations to suggest here, even though I feel like just being able to
> tweak defaults with a global callback as proposed would just do the trick.
>
> [0] https://code.djangoproject.com/ticket/22609
> [1] https://github.com/django/django/blob/master/django/
> forms/models.py#L111
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-developers/CALC3Kad7%2BPrkJC0Cz2SsoB374%
> 2BNxuJcN7z_2pANOQzpdBneBFg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-developers/CALC3Kad7%2BPrkJC0Cz2SsoB374%2BNxuJcN7z_2pANOQzpdBneBFg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM1pKMq0mCZLwQ6GD4Ti50TQ0rdO6BXRaN213oXedPkC_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to