unless assign_perm invalidates the user instance's perm cache, that's not a huge surprise.
usr123
kezabelle: I did not understand.
fmarco joined the channel
lqez has quit
fmarco has left the channel
kezabelle: Also, instead of a foreign key from user to plant I have an m2m, does that make any difference?
agrawalritesh has quit
Haudegen joined the channel
VikingHoarder joined the channel
aossama joined the channel
agrawalritesh joined the channel
I have the following hierarchy. Plant -> Site -> Unit -> Zone. A user can be associated with instances of any of the above. User has 4 m2m keys with each of them. But at one time he can be associated with instances of only one of the models. Now I need to return instances related to the user. How do I do it?
I also need to return the children of the instances the user is related to, so it user is related to plant1 and plant1 is a foreign key to site1, site2, site3. I need to return all of those.
Ahuj joined the channel
detseg has quit
ticketbot has quit
ticketbot joined the channel
agrawalritesh has quit
Natureshadow joined the channel
sydbarret
in jquery i have this --- > var action = $('#'+i+'-action').text(); which prints "OK" in the console but when I do if action=="OK"" doesnt come true
jtiai
sydbarret: Are you sure that is exacgtly "OK" that there are no whitespaces anywhere?
how to fix in those cases? because that was inserted like that in th model innit?
jtiai
And well I guess you have to figure out the fix yourself...
C0r3 joined the channel
debnet has quit
sydbarret
have you used that crispy in forms?
i have a formset that is rendered without spaces
jtiai
I don't use any crispy in my forms.
sydbarret
what do you use for tabular data, just css or bootstrap?
usr123
I have the following hierarchy. Plant -> Site -> Unit -> Zone. A user
can be associated with instances of any of the above. User has 4 m2m
keys with each of them. But at one time he can be associated with
instances of only one of the models. Now I need to return instances
related to the user. How do I do it? I also need to return the children of the instances the user is related to, so it user is related to plant1 and plant1 is a foreign
key to site1, site2, site3. I need to return all of those.
Apologies, It turned out bad
berto_ joined the channel
berto_ has quit
Does anyone have a response for my query?
berto_ joined the channel
searchingfortao joined the channel
berto_
some attribute of my model are slow to calculate but depend on others model/table ... how can I cache the result up to when the row on the table on which he depend change?
usr123 has quit
jtiai
berto_: Caching is easy... cache invalidation is really hard thing to do...
berto_
jtiai, how people generly proced on this kind of problem ... when you have a attribute or your module which are not field on the db table and are slow to compute? Any reference on what should I look ?
agrawalritesh has quit
blip99 joined the channel
xcm joined the channel
agrawalritesh joined the channel
FunkyBob
berto_: as always... it depends
you can used, for instance, cached_property so it's only calculated once per instance [from django.utils.functional]
CtrlC joined the channel
csotelo joined the channel
BuffaloSoldier joined the channel
usr123 joined the channel
berto_
FunkyBob, I used cached_property but does not seam to make a great difference .... if I do twice a get request on the same model it seam have the same time reponse
BSLang joined the channel
chasonchaffin has quit
usr123
I have a hierarchy as following. Plant -> Site -> Unit -> Zone. A user have m2m fields with each of them but can be assigned to instances of only one model at a time (Head of Department). I need to get all the instances under the user. I also need the child instances (for instances the current instance is foreign key to). I am using this logic currently: https://dpaste.de/E1o9
andyhoang joined the channel
BSLang has quit
sydbarret has quit
theo_moore joined the channel
CtrlC has quit
safwan joined the channel
lizx6451 has quit
lizx6451 joined the channel
tdy joined the channel
berto_
FunkyBob, I actually calculated more attentivly and even if is still very slow ... the reponse is more fast
so chacted_property helped
tdy has quit
TripFandango has quit
BSLang joined the channel
sunil_bansal joined the channel
bullicon joined the channel
yeshurun joined the channel
dodobas
is it possible to access M2M table (one that has been automatically created), with ORM ?
or the only way is to specify a `through` model ?
moldy
dodobas: yes, it is possible. something like `.through`
dodobas
moldy: oh, nice, tnx
moldy
don't remember exactly right now
knbk
Model.m2m_field.through
moldy
:)
mintograde joined the channel
BuffaloSoldier has quit
usr123
Any response for my query?
moldy
usr123: what is the problem? too slow?
usr123
moldy: I need to return instances related to the user and the instances which have the above instances as a foreign key.
My hierarchy is as such : Plant -> Site -> Unit -> Zone. Each has a m2m field with user.
So if user(head of department) is a Plant level user, I need to return all the plants related to that user and all the sites related to all these plants.
moldy
usr123: you showed us your current code, but you did not tell us what the problem with the code is
moldy: Yeah, It's kind of hectic to construct querysets like that. And I may have other cases coming up. So I wanted to know what is the standard way of dealing with user-instance relationships
moldy
"hectic"?
there is no standard, since use-cases are different. many projects just work with a plain FK or M2M, but your case seems to be more complex
usr123
moldy: So I have 4 levels and HOD can be assigned to anyone of these level's instances. I would not know in advance, but I have this info stored in HOD.level. Because I can't know what models to query, I need to write generic code. But like this I would have to construct querysets for each need. I wanted to know if there is a standard library which handles these relationships.
moldy: Was looking at django-guardian, and they have a way to return all the objects related to user, but it does not work for some reason
fub
So Im using django-import-export in my admin area. When importing, I get a lot of errors because of violating not-null constraints.
When I am in the admin form however, I can save (without putting values in the field)
moldy
usr123: i would solve a specific case first and then generalize it
fub
So I guess the only way to solve is by using null=True on the model fields?
usr123
moldy: Ok, Thanks. And thanks for the code as well. I didn't know I could do plant__in
moldy
usr123: there is nothing wrong with a few ifs / elifs here. KISS.
robotme joined the channel
if HOD.level == 'plant': # query plant models. elif HOD.level == 'site': query site models
fub: no
fub: in general, don't change your models just to make some utility package happy
chasonchaffin joined the channel
fub: if having null=False on those models makes sense from a data modelling point of view, then stick with it. adjust your import / export code to pass proper values when saving.
btw, django-import-export is nice for simple cases, but if your import is highly customized, i recommend to just roll your own thing
kiloreux_ has quit
ram0n has quit
fub
moldy: yeah I figured out I need to write my own import because I fighting already with it for some things
moldy: where can using null=True be a problem?
moldy
you can also customize django-import-export, it supports custom fields and such
usr123
moldy: Yeah, that would be the perfect way to do it. But this software is client specific, and client keeps changing so I wanted to write something so that even if new models get added and foreign key relationships change, the code still works
moldy
but at some point, it becomes easier to write your own thing. i am currently working on a 1k lines import module based on django-import-export. i wish i had just written my own ;)
chasonchaffin has quit
usr123
moldy: But yeah, ifs and elifs would be much cleaner compared to this.
moldy
fub: whenever something should not be empty / NULL in the database
usr123: models are static. when a new model is added, you are already changing your code.
usr123
moldy: Ok, thanks for the advice, I should KISS
fub
moldy: the fields in question are only text fields, so I dont think it can be a problem here, right?