iommirocks / iommi

Your first pick for a django power cord
http://iommi.rocks
BSD 3-Clause "New" or "Revised" License
784 stars 51 forks source link

Docs - example in "How do I control what Q is produced?" #413

Closed berycz closed 1 year ago

berycz commented 1 year ago

(from our convo on discord)

how about an example in https://docs.iommi.rocks/en/latest/cookbook_queries.html#how-do-i-control-what-q-is-produced

class AlbumsTable(Table):
    class Meta:
        auto__model = Album

        query__form__fields__ninetees = iommi.Field.boolean(
            display_name=_("the '90s"),
        )

        @staticmethod
        def query__filters__ninetees__value_to_q(value_string_or_f, **_):
            if value_string_or_f == "1":
                return Q(year__gte=1990) & Q(year__lte=1999)
            return Q()

(I haven't tested it, but should work)