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

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

Open
robrichter opened this issue May 5, 2021 · 0 comments
Open

Comments

@robrichter
Copy link

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'
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