These are chat archives for django/django

18th
Sep 2018
Karmenzind
@Karmenzind
Sep 18 2018 00:25
@morenoh149 These threads send concurrent requests for stress testing. What do you mean by materialized views?They are from existing project and I cannot change the models. I also want to know why 😂
Harry Moreno
@morenoh149
Sep 18 2018 00:35
ah if it's out of your control that's fine
materialized views are usually added to a project later when you have different consumer's of the data. You'd rarely want to power a django model off of a materialized view unless you want to put in work to get more performance.
Karmenzind
@Karmenzind
Sep 18 2018 00:54
thanks. gonna read it later
Karmenzind
@Karmenzind
Sep 18 2018 01:23
I've already read it but i'm a little confused. Do you mean inherited models actually created materialized views? If so, how to fix the deadlock? @morenoh149
Himanshu Shankar
@iamhssingh
Sep 18 2018 04:25

@iamhssingh Can’t you override get_queryset?

@sp1rs No. I want to have this permission every where in the system (which includes the RESTful APIs & Admin Panel). I can use Filter Backend in views separately. That is one solution, but I was thinking of some global permission thing.

Shashank Parekh
@sp1rs
Sep 18 2018 04:42
@iamhssingh You can write mixin which will do authorization on user.
And that mixin you can used in APIs as well as in Admin panel.
Himanshu Shankar
@iamhssingh
Sep 18 2018 04:50
@sp1rs Nevermind, I got it.
How about this then?
  1. I create a function that determines whether an user have permission to work on provided object: has_perm(user, obj). Use it to return True or False.
  2. Like you said earlier, I create two filter, each for admin & REST API and use it at both the places in addition to has_perm.
Shashank Parekh
@sp1rs
Sep 18 2018 04:52
@iamhssingh sounds good, You can use mixin :D in this. Mixin class with has_perm method.
Himanshu Shankar
@iamhssingh
Sep 18 2018 05:48
Thanks @sp1rs
Himanshu Shankar
@iamhssingh
Sep 18 2018 10:15
Can I change a value of attribute from clean_fields()?
in Model
Karmenzind
@Karmenzind
Sep 18 2018 11:28
@morenoh149 I added force_insert=True to C.save() and then the deadlocks disappeard. But I don't know if it will cause other side effects.
Harry Moreno
@morenoh149
Sep 18 2018 15:53
@Karmenzind I've never done model inheritance https://docs.djangoproject.com/en/2.1/topics/db/models/#model-inheritance I'd advise against it if possible
the model inheritance docs do not mention materialized views so I'm assuming you don't have matviews either