Error with Column Name in Django

0

I have a problem with a database in SqlServer 2008, I'm doing some reports to show them in a Django project from a production database, which is used by another system, I have the following view:

class DetalleDeuda(ListView):
    model = T090Deudas
    template_name = 'deudas.html'
    context_object_name = 'deudas'    

    @method_decorator(permission_required('deudas.ver_deuda_prescrita',reverse_lazy('usuarios:permiso_denegado')))
    def dispatch(self, *args, **kwargs):
        self.contribuyente = self.kwargs['contribuyente']
        return super(DetalleDeuda, self).dispatch(*args, **kwargs)

    def get_context_data(self, **kwargs):        
        context = super(DetalleDeuda, self).get_context_data(**kwargs)
        contrib = T001Contribuyente.objects.get(c001cod_cont=self.contribuyente)
        context['contribuyente'] = contrib        
        return context

    def get_queryset(self):
        queryset = T090Deudas.objects.filter(c090cod_cont=self.contribuyente)
        return queryset 

But unfortunately the previous programmers named a column of the table T090Deudas, like c090year, so when I show the result in my template I get the following error:

  

Exception Type: UnicodeDecodeError

     

Exception Value: 'ascii' codec can not decode byte 0xc3 in position 19: ordinal not in range (128)

I can not change the name of the column, since this would mean altering the other system that is made in Visual Basic and it is quite large, I would like to know if it is possible to do something or simply I should do the query omitting that column.

    
asked by inkarri 27.07.2016 в 02:20
source

3 answers

1

Test

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    
answered by 02.08.2016 в 16:11
1

where you defined the view and the corresponding model in python you got the charset header, if not, try adding it should solve the problem because it is an error in the interpreter:

# -*- coding: utf-8 -*-

or

# -*- coding: iso-8859-1 -*-
    
answered by 30.03.2017 в 17:03
1

Use the db_column attribute in the definition of the field in the model.

link

Example:

c090year = models.CharField(max_length=10, db_column='c090Año')
    
answered by 23.03.2018 в 10:18