nautobot.apps.filters
¶
Filterset base classes and mixins for app implementation.
nautobot.apps.filters.BaseFilterSet
¶
Bases: django_filters.FilterSet
A base filterset which provides common functionality to all Nautobot filtersets.
Source code in nautobot/utilities/filters.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 |
|
add_filter(new_filter_name, new_filter_field)
classmethod
¶
Allow filters to be added post-generation on import.
Will provide <field_name>__<lookup_expr>
generation automagically.
Source code in nautobot/utilities/filters.py
errors()
property
¶
Extend FilterSet.errors to potentially include additional errors from settings.STRICT_FILTERING.
Source code in nautobot/utilities/filters.py
get_filters()
classmethod
¶
Override filter generation to support dynamic lookup expressions for certain filter types.
Source code in nautobot/utilities/filters.py
is_valid()
¶
Extend FilterSet.is_valid() to potentially enforce settings.STRICT_FILTERING.
Source code in nautobot/utilities/filters.py
nautobot.apps.filters.CustomFieldModelFilterSetMixin
¶
Bases: django_filters.FilterSet
Dynamically add a Filter for each CustomField applicable to the parent model. Add filters for extra lookup expressions on supported CustomField types.
Source code in nautobot/extras/filters/mixins.py
nautobot.apps.filters.FilterExtension
¶
Class that may be returned by a registered Filter Extension function.
Source code in nautobot/extras/plugins/__init__.py
nautobot.apps.filters.NaturalKeyOrPKMultipleChoiceFilter
¶
Bases: django_filters.ModelMultipleChoiceFilter
Filter that supports filtering on values matching the pk
field and another
field of a foreign-key related object. The desired field is set using the to_field_name
keyword argument on filter initialization (defaults to slug
).
Source code in nautobot/utilities/filters.py
get_filter_predicate(v)
¶
Override base filter behavior to force the filter to use the pk
field instead of
the natural key in the generated filter.
Source code in nautobot/utilities/filters.py
nautobot.apps.filters.NautobotFilterSet
¶
Bases: BaseFilterSet
, CreatedUpdatedModelFilterSetMixin
, RelationshipModelFilterSetMixin
, CustomFieldModelFilterSetMixin
This class exists to combine common functionality and is used as a base class throughout the codebase where all of BaseFilterSet, CreatedUpdatedModelFilterSetMixin, RelationshipModelFilterSetMixin and CustomFieldModelFilterSetMixin are needed.
Source code in nautobot/extras/filters/__init__.py
nautobot.apps.filters.RelatedMembershipBooleanFilter
¶
Bases: django_filters.BooleanFilter
BooleanFilter for related objects that will explicitly perform exclude=True
and isnull
lookups. The field_name
argument is required and must be set to the related field on the
model.
This should be used instead of a default BooleanFilter
paired method=
argument to test for the existence of related objects.
Example
has_interfaces = RelatedMembershipBooleanFilter( field_name="interfaces", label="Has interfaces", )
Source code in nautobot/utilities/filters.py
nautobot.apps.filters.RelationshipModelFilterSetMixin
¶
Bases: django_filters.FilterSet
Filterset for relationships applicable to the parent model.
Source code in nautobot/extras/filters/mixins.py
nautobot.apps.filters.SearchFilter
¶
Bases: MappedPredicatesFilterMixin
, django_filters.CharFilter
Provide a search filter for use on filtersets as the q=
parameter.
See the docstring for nautobot.utilities.filters.MappedPredicatesFilterMixin
for usage.
Source code in nautobot/utilities/filters.py
nautobot.apps.filters.StatusModelFilterSetMixin
¶
nautobot.apps.filters.TenancyModelFilterSetMixin
¶
Bases: django_filters.FilterSet
An inheritable FilterSet for models which support Tenant assignment.
Source code in nautobot/tenancy/filters/mixins.py
nautobot.apps.filters.TreeNodeMultipleChoiceFilter
¶
Bases: NaturalKeyOrPKMultipleChoiceFilter
Filter that matches on the given model(s) (identified by slug and/or pk) as well as their tree descendants.
For example, if we have:
Region "Earth"
Region "USA"
Region "GA" <- Site "Athens"
Region "NC" <- Site "Durham"
a NaturalKeyOrPKMultipleChoiceFilter on Site for {"region": "USA"} would have no matches, since there are no Sites whose immediate Region is "USA", but a TreeNodeMultipleChoiceFilter on Site for {"region": "USA"} or {"region": "Earth"} would match both "Athens" and "Durham".
Source code in nautobot/utilities/filters.py
generate_query(value, qs=None, **kwargs)
¶
Given a filter value, return a Q
object that accounts for nested tree node descendants.