def generate_auto_fields(self):
        # ignore the original date field
        self.ignore = True
        datetime_str = None

        # create an alias for the unix timestamp extraction
        epoch_alias = '{0}__{1}'.format(self.field.get_name(), 'epoch')

        if self.name == 'all':
            datetime_str = self.field
            self.add_to_table(AllEpoch(datetime_str, table=self.table, cast=self.cast), epoch_alias)
            # do not add the date order by for "all" grouping because we want to order by rank
            return
        elif self.name == 'none':
            datetime_str = self.field
            self.add_to_table(Epoch(datetime_str, table=self.table, cast=self.cast), epoch_alias, add_group=True)
        else:
            group_names = default_group_names
            if self.name == 'week':
                group_names = week_group_names

            group_name_index = group_names.index(self.name) + 1
            for group_name in group_names[0:group_name_index]:
                field_alias = '{0}__{1}'.format(self.field.get_name(), group_name)
                auto_field = group_map[group_name](self.field, table=self.table, cast=self.cast)
                self.add_to_table(auto_field, field_alias, add_group=True)

                # check if this is the last date grouping
                if group_name == self.name:
                    datetime_str = self.field
                    self.add_to_table(
                        GroupEpoch(
                            datetime_str,
                            date_group_name=group_name,
                            table=self.table,
                            cast=self.cast,
                        ),
                        epoch_alias,
                        add_group=True
                    )

        if self.desc:
            self.table.owner.order_by('-{0}'.format(epoch_alias))
        else:
            self.table.owner.order_by(epoch_alias)
Generates any auto fields needed to properly group this date part.
dataset/ETHPy150Open ambitioninc/django-query-builder/querybuilder/fields.py/DatePartField.generate_auto_fields