-
Notifications
You must be signed in to change notification settings - Fork 757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal for getting help_text from model fields #754
Comments
Hi @jter. I feel like this has been talked about before, but I can't find the relevant discussion. In short, this suggestion works well for FilterSets like... class UserFilter(FilterSet):
class Meta:
model = User
fields = ['username', 'email', 'name', ...] Adding the However, class ArticleFilter(FilterSet):
class Meta:
model = Article
fields = {
'author': ['exact', 'startswith', 'endswith', ...],
'title': ['exact', 'startswith', 'endswith', ...],
'published_at': ['exact', 'isnull'],
} In this case, adding in the model's
This would be fairly straightforward to achieve with a custom FilterSet base class: class HelpfulFilterSet(django_filters.FilterSet):
@classmethod
def filter_for_field(cls, f, name, lookup_expr):
filter = super(HelpfulFilterSet, cls).filter_for_field(f, name, lookup_expr)
filter.extra['help_text'] = f.help_text
return filter |
Thank you for your illustrating, clear and useful. |
It would be great that filters of
FilterSet
could gethelp_text
from fields of Models. This feature can save some repetitive work when we needhelp_text
for auto-generated docs from model fields without redefining the filters inFilterSet
. Could this proposal be a good idea?The text was updated successfully, but these errors were encountered: