Skip to content

Doesn't work if model field name is different from db column name #25

Description

@robrichter

Problem description

I have unmanaged model with geometry that I want to serve as MVT. Problem is that field name differs from table name.

class Obec(models.Model):
    id = models.IntegerField(db_column="kod", primary_key=True)
    name = models.CharField(max_length=255, db_column="nazev")
    geom = models.MultiPolygonField(srid=5514)
    okres_code = models.IntegerField(db_column="okres_kod")

    class Meta:
        managed = False
        db_table = "g_obec_p"

I found that djangorestframework-mvt collects non geom columns and then in method _create_select_statement() calls self.only(*columns).query.sql_with_params()
And that's the problem. QuerySet method only works with fields not columns.

So in my case it ends with error:

    raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: Obec has no field named 'orp_kod'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions