Beispiel #1
0
    def __init__(self, handler, row_session, field):
        self.row_session = row_session
        self.handler = handler
        self.field = field
        self.rel = rel = field.rel
        self.to = to = rel.to
        self.map_cache = {}
        self.fk_cache = {}
        self.explicit_uk_fields = tuple(
            handler._meta.fk_matchers.get(field.name) or ())
        self.is_translated = hasattr(self.to, "_parler_meta")
        self.translated_fields = self.to._parler_meta.root_model._meta.get_fields(
        ) if self.is_translated else []
        self.translated_field_names = [f.name for f in self.translated_fields]

        uk_fields = dict((f.name, f) for f in get_model_unique_fields(to))
        uk_fields.update((fname, None) for fname in self.explicit_uk_fields)

        # TODO: can explicit fields be used to map stuff
        uk_fields.update(
            (f.name, f) for f in get_model_possible_name_fields(to))

        self.uk_fields = uk_fields
        self.reverse_fields = list(
            itertools.chain(self.explicit_uk_fields,
                            [f for f in uk_fields if f not in ("id", "pk")],
                            ["pk"]))
        manager = to.objects
        if issubclass(to, TranslatableModel):
            manager = manager.language(handler.language)

        self.manager = manager
Beispiel #2
0
    def __init__(self, handler, row_session, field):
        self.row_session = row_session
        self.handler = handler
        self.field = field
        self.rel = rel = field.rel
        self.to = to = rel.to
        self.map_cache = {}
        self.fk_cache = {}
        self.explicit_uk_fields = tuple(handler._meta.fk_matchers.get(field.name) or ())
        self.is_translated = hasattr(self.to, "_parler_meta")
        self.translated_fields = self.to._parler_meta.root_model._meta.get_fields() if self.is_translated else []
        self.translated_field_names = [f.name for f in self.translated_fields]

        uk_fields = dict((f.name, f) for f in get_model_unique_fields(to))
        uk_fields.update((fname, None) for fname in self.explicit_uk_fields)

        # TODO: can explicit fields be used to map stuff
        uk_fields.update((f.name, f) for f in get_model_possible_name_fields(to))

        self.uk_fields = uk_fields
        self.reverse_fields = list(itertools.chain(
            self.explicit_uk_fields,
            [f for f in uk_fields if f not in ("id", "pk")],
            ["pk"]
        ))
        manager = to.objects
        if issubclass(to, TranslatableModel):
            manager = manager.language(handler.language)

        self.manager = manager