Closed LECbg closed 4 years ago
Thank you for your proposal :). I will investigate and test your idea during the weekend, it's looking really good, and I will probably implement it
To keep compatibility with the old versions, the view definition is still an attribute, but now you can provide both, string and a function as a view definition. Providing a function allows you to do what you want. The function must return string.
Does that solution suit you? :)
Yeah, of course. Thank you!
As far as I've been able to find, this is the only place where the class attribute
view_definition
is used:https://github.com/BezBartek/django-db-views/blob/c815737fbb0bbb0a2bd65e10d290538759c76527/django_db_views/autodetector.py#L106
Would you consider turning this attribute into a method? I think this would allow to get some advantages from Django itself, since part of the query could be built by the ORM, just like with RunPython migrations. To explain myself better, consider the following example (using the one provided in the
README
):My use case includes the use of
union()
, which doesn't allow annotations afterwards, so I would have to callROW_NUMBER
manually. Despite this, this approach would still be worth it:I haven't tested this, so I don't if there's anything I'm missing that prevents from doing this. Any feedback would be appreciated.