Example #1
0
    def __get__(self, instance):
        if instance is None:
            return self

        value = getattr(instance, self.attname)

        from djangae.forms.fields import decode_pk
        from djangae.db.utils import get_model_from_db_table

        if value is None:
            return None

        model_ref, pk = decode_pk(value)
        try:
            return get_model_from_db_table(model_ref).objects.get(pk=pk)
        except AttributeError:
            raise ImproperlyConfigured("Unable to find model with db_table: {}".format(model_ref))
Example #2
0
    def __get__(self, instance):
        if instance is None:
            return self

        value = getattr(instance, self.attname)

        from djangae.forms.fields import decode_pk
        from djangae.db.utils import get_model_from_db_table

        if value is None:
            return None

        model_ref, pk = decode_pk(value)
        try:
            return get_model_from_db_table(model_ref).objects.get(pk=pk)
        except AttributeError:
            raise ImproperlyConfigured("Unable to find model with db_table: {}".format(model_ref))