Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field not exist checking #17

Open
isergey opened this issue Mar 14, 2012 · 0 comments
Open

Field not exist checking #17

isergey opened this issue Mar 14, 2012 · 0 comments

Comments

@isergey
Copy link

isergey commented Mar 14, 2012

    def render(self, context):
        key = self.queryset_var.var
        value = self.queryset_var.resolve(context)
        order_by = context['request'].field
        if len(order_by) > 1:
            try:
                try:
                    field_name = order_by
                    if order_by[0] == '-':
                        field_name = order_by[1:]
                    # check for order field exist in model
                    value.model._meta.get_field(field_name)
                    context[key] = value.order_by(order_by)
                except FieldDoesNotExist as e:
                    if settings.DEBUG == True:
                        raise e

            except template.TemplateSyntaxError:
                if INVALID_FIELD_RAISES_404:
                    raise Http404('Invalid field sorting. If DEBUG were set to ' +
                    'False, an HTTP 404 page would have been shown instead.')
                context[key] = value
        else:
            context[key] = value

        return ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant