Created
August 6, 2021 17:19
-
-
Save om2c0de/d985e41652ba73120a9f7a4ad98a8d1e to your computer and use it in GitHub Desktop.
Filtering multiple types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TypeFilter: | |
name = models.CharField(max_length=255) | |
class TypeFilterCondition: | |
# Filtering types | |
physical_object_type = models.ForeignKey(PhysicalObjectType, related_name='+', on_delete=models.CASCADE) | |
research_type = models.ForeignKey(ResearchType, related_name='+', on_delete=models.CASCADE) | |
# Fields filtering possibilities | |
physical_object_q_filtering_options = models.JSONField() | |
research_conditions_q_filtering_options = models.JSONField() | |
# Filter object itself | |
filter = models.ForeignKey(TypeFilter, related_name='conditions', on_delete=models.CASCADE) | |
# Usage example: | |
# Get types | |
# p_type = self.physical_object_type | |
# r_type = self.research_type | |
# Get objects with data | |
# physical_objects_q = Q() | |
# physical_objects_q |= Q(option) for option in self.physical_object_q_filtering_options | |
# physical_objects = PhysicalObject.objects.filter(physical_objects_q) | |
# Get researches with data | |
# researches_q = Q() | |
# researches_q |= Q(option) for option in self.research_conditions_q_filtering_options | |
# researches = Research.objects.filter(researches_q) | |
# Join researches and ph_objects in same DataFrame using their ids | |
# ... | |
# format QuerySets to dataframes with read_frame() and then: | |
# df = pd.merge( | |
# physical_objects_df, | |
# researches_df, | |
# left_on = "id", | |
# right_on = "physical_object__id", | |
# ) | |
# return df to frontend. same format like now | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment