-
Notifications
You must be signed in to change notification settings - Fork 771
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
ChoiceFilter callable choices #710
Comments
That's the question isn't is? 🙂 Can you explain your use-case a bit so we can see? Thanks! |
Indeed! 🙂 I think currently in Some naive example: class AccountTransactionType(models.Model):
name = models.CharField(max_length=100)
class AccountTransaction(models.Model):
transaction_type=models.ForeighKey(AccountTransactionType)
transaction_date=models.DateTimeField()
#....
# ------------
def recent_type_choice_fn():
# Lets get some more recent account type
return AccountTransaction.objects.filter(
transaction_date__gt=(timezone.now() - timezone.delta(days=30))
).values_list('transaction_type', 'transaction_type__name')
class AccountingTransactionFilter(django_filter.FilterSet):
transaction_type = ChoiceFilter(
choices=recent_type_choice_fn,
#....
)
Here we want to show transaction type with recent entries e.g. last 30 days, in the filter. However, Let me know of your thoughts, thanks! |
It might not also be a bad idea for me to add a test in 680 ensuring that choices are resolved during FilterSet form creation instead of during filter instantiation. |
Yep rpkilby, I gave PR #680 a quick test, and it looks like the PR solves the issue. 👍 Thanks for the PR! When will it likely be released? 🙂 |
It'll be a week or two (at least). I need to finish 1.0.3 and then look at the proposals for 1.1 (which includes this one.) If you need it before then I'd suggest installing from the branch |
version 1.1 sounds good, thanks! |
* Add test cases from PR 639. Thanks @michael-mri! * Fix tests for null choice iterator * Add more null value tests * Add null choice to various (Model)ChoiceFields * Fix django < 1.11 field iterator handling * Resolve #710 - add test for lazy callable choices
Hello,
For ChoiceFilter (and other related ones), is it possible, or will it make sense, to have the 'choices' callable to behave like the ChoiceField in django, where 'it is evaluated each time the field’s form is initialized'?
https://docs.djangoproject.com/en/1.11/ref/forms/fields/#choicefield
(I am happy to draft a PR if this sounds a reasonable feature request)
Thanks!
The text was updated successfully, but these errors were encountered: