I was thinking of support for just the DDL commands, with read-only data 
access.

IMHO, There are actually two major caveats with trying to go for fully 
managed support for Views
1. Insert, update and delete varies between DBs and SQLite doesn't support 
it at all
2. Materialized Views

For (1), I was hoping the ViewModel base class can use an abstract class 
with a NotImplemented error for the C*UD logic and allow just read-only 
permission by default. The dev can choose to enable the permissions for 
insert/update. This is imperative as you've pointed out, the design of the 
View is very subjective and will vary from project to project and even 
within projects. So it's best left to the developer to define the data 
manipulation that best suits their use case. 

Regarding (2), I was considering it to be out of scope for this proposal as 
that introduces too much complexity with just one task.


On Tuesday, 22 February 2022 at 10:18:05 UTC+1 al...@interia.eu wrote:

> Hi,
>
> I am using the same approach, migrations with RunSQL and model and in most 
> cases it is working well.
>
> Introduction of supporting views is easy at a first glance. But when you 
> think more then it is not so easy. People would see the view in admin 
> panel, but admin panel is based on an idea that every model has primary key 
> but view hasn't got one.
> So it would be required to disable adding and editing of data - only 
> reading for that model. But some databases allow to insert data through a 
> view so it became an issue how to support that.
> It also involves support of queryset, migrations, reverse engineering 
> (inspectdb), generic views and some other details of the views in different 
> database engines.
>
>
>
> Currently, I just use the migrations to do a RunSQL and then I make a 
> model with the Meta option managed set appropriately. It works for me, but 
> perhaps something a bit more convenient is in order these days.
>
>  
>
> *From:* django-d...@googlegroups.com <django-d...@googlegroups.com> *On 
> Behalf Of *Vasanth Mohan
> *Sent:* Monday, February 21, 2022 8:21 AM
> *To:* Django developers (Contributions to Django itself) <
> django-d...@googlegroups.com>
> *Subject:* Adding Support for DB Views
>
>  
>
> Are there any plans to support DB Views ? Would the team be interested in 
> mainlining it if there is a PR for it ? 
>
>  
>
> I tend to use DB Views on Postgres at my day job and wouldn't mind adding 
> basic support across Django's supported DBs. I'll probably take inspiration 
> from Knex.js 
> <https://us-east-2.protection.sophos.com?d=knexjs.org&u=aHR0cHM6Ly9rbmV4anMub3JnLyNTY2hlbWEtY3JlYXRlVmlldw==&i=NWVjN2YxNzUxNGEyNzMxNmMyMGRkZGU1&t=VlZ3M2llM3EwdHFtZG03WnZMTFBmdDkxUG1nNFNOUEFwYSt2ZUoyY2dmOD0=&h=b1dc1a4a21604d3ea180a144eae9d276>
>  
> to implement it.
>
> I'm imagining something along the lines of,
>
> class NewView(models.ViewModel):
>
>          def view_qs(self):
>                 return qs # Define with QS  to be used in CREATE VIEW 
> App_ViewModel as QS;
>
>  
>
> migrations.CreateViewModel( ... )
>
> migrations.DeleteViewModel( ... )
>
> migrations.UpdateViewModel( ... )
>
>    
>
>  
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-develop...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-developers/e009c1bd-8a68-486a-8b7f-7c3d9e3553een%40googlegroups.com
>  
> <https://us-east-2.protection.sophos.com?d=google.com&u=aHR0cHM6Ly9ncm91cHMuZ29vZ2xlLmNvbS9kL21zZ2lkL2RqYW5nby1kZXZlbG9wZXJzL2UwMDljMWJkLThhNjgtNDg2YS04YjdmLTdjM2Q5ZTM1NTNlZW4lNDBnb29nbGVncm91cHMuY29tP3V0bV9tZWRpdW09ZW1haWwmdXRtX3NvdXJjZT1mb290ZXI=&i=NWVjN2YxNzUxNGEyNzMxNmMyMGRkZGU1&t=RGFkbkVWSFB3MS90WENZby83RnZTSTltUGVNK2hNYkxuWXZhZXc1WXlZTT0=&h=b1dc1a4a21604d3ea180a144eae9d276>
> .
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-develop...@googlegroups.com.
>
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-developers/b5f0b99b068a4ea192797708d4f5037d%40Exchange.ISS.LOCAL
>  
> <https://groups.google.com/d/msgid/django-developers/b5f0b99b068a4ea192797708d4f5037d%40Exchange.ISS.LOCAL?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/329945c3-8981-4f9f-935e-830516181d2cn%40googlegroups.com.

Reply via email to