I have an app where the admin interface is heavily used. There are a lot of records and the call to .distinct() for the admin filter list is very expensive. Is there any way to cache those unique values? I tried caching at the template level but the problem is the template cannot construct query parameters properly if it's cached
WeiJunLi has quit
moldy
it's really the disinct() that is too expensive, you don't do n+1 queries?
newbsie has quit
the_drow has quit
Fingel
yes, it's the distinct(). It has to do a full table scan for each filterable field
well, string fields at least
agentorange joined the channel
lborda has quit
jaddison joined the channel
lborda joined the channel
moldy
i guess you could do caching on a custom admin class?
fission6 joined the channel
we are talking about ``list_filter``?
Fingel
yea, list_filter
moldy
well, if you look at the docs, you can for example use a custom SimpleListFilter subclass
and do whatever caching logic you want there
Fingel
I will look into that, thanks
erg0dic has quit
moldy
though maybe it would be worthwhile to think about not using the admin in the first place ;)
the_rat_ joined the channel
mstrcnvs
moldy: +1
overallrhino joined the channel
WeiJunLi joined the channel
bx2_ joined the channel
insermod has quit
bx2 has quit
WeiJunLi has quit
npo joined the channel
the_rat_ has quit
Fingel
yea I know, but my predecessor modified the hell out of it now people depend on it, sucks
royendgel has quit
XofP has quit
moldy
i am guilty of that, too :p
lejedi76 has quit
Fingel
and its 1.4!
frewsxcv_
Are there any resources for how to create generic django apps suitable for libraries
Specifically, how to handle model relations with other non generic models
frewsxcv_: i am not sure what your exact question is, but it sounds a little like you are asking about "swappable" or "deferred" models
WeiJunLi has quit
frewsxcv_: there is an unofficial / undocumented solution for this is in django, and a third-party app or two, but no clear de-facto standard
adelq has quit
ai88 has quit
WeiJunLi joined the channel
garrypolley joined the channel
if you can somehow avoid the problem (e.g. by not defining models in your app at all), tat's the best solution ;)
mehola joined the channel
audio has quit
retailify joined the channel
Bash4 has quit
Bash4 joined the channel
frewsxcv_
Via mixing?
Mixing*
Mixins**
fission6 has quit
moldy
unfortunately it's more complicated then that
frewsxcv_
For example, I want to create a generic app for associating Tags with a model
mstrcnvs
frewsxcv_: any model?
moldy
like django-taggit?
frewsxcv_
A single model I know at runtime
garrypolley has quit
moldy
one way (that has drawbacks) is to use GenericForeignKey
frewsxcv_
Not N number ofmodels at runtime
moldy
ok
mehola has quit
maybe take a look at django-swappable. not sure how well it works at the moment.
mstrcnvs
frewsxcv_: but tags can be associated with model A and B at the same time, in the same runtime
correctw
?
retailify has quit
frewsxcv_
Having a model builder function could maybe even work
moldy
you bascially want to do what django does wih AUTH_USER_MODEL, right?
frewsxcv_
I think so
slav0nic has quit
mstrcnvs
frewsxcv_: if you answer my question we can know for sure :)
frewsxcv_
mstrcnvs: no
I don't need it to be associated with A and B
Just a known A
mstrcnvs
nice
frewsxcv_
Just like ForeignKey
mstrcnvs
so you want a swappable
moldy
it is an unsolved problem. intentionally not documented. look at django-swappable, maybe you can use it, or steal some code from them, or at the very least learn from their mistakes.
mstrcnvs
swappable ForeignKey just like AUTH_USER_MODEL like moldy said
frewsxcv_
(I'm the maintainer of taggit btw)
But this is for something unrelated to tags
moldy
i personally believe it would be great to have an official solution for this, but there is none at the moment
mstrcnvs
and why you'd give us the wrong example?
fnstudio joined the channel
moldy
frewsxcv_: oh, that's nice :)
frewsxcv_
Just using it as an example
I'll look into django-swappable, thanks
Just using it as an example
disgrntld has quit
mstrcnvs
if it's not for tags, why say tags...
aron_kexp has quit
riclima_ joined the channel
frewsxcv_
It got the point across didn't it 😀
Real usage is a little more complicated and not worth going into details
Dockit1 joined the channel
xall joined the channel
WeiJunLi_ joined the channel
WeiJunLi_ has quit
WeiJunLi_ joined the channel
WeiJunLi has quit
pajinek1 has quit
Hm. This django-swappable-models looks like it'll work. Unfortunate there's not an official solution, but so be it
cnk
Does anyone have an example of doing A/B testing in Django? or doing feature flags so a portion of your audience gets beta functionality?
npo has quit
going to need runtime algorithm substition some time soon and would like to do a little reading
Electrometro joined the channel
SecondForm_Glenn has quit
xall has quit
woltman joined the channel
linx has quit
zoolook has quit
alexhayes joined the channel
alexhaye1 joined the channel
moldy
frewsxcv_: /aw
oops
alexhayes has quit
CrypticSquared joined the channel
frewsxcv_: for example, if your app can provide a view with a get_model() or get_object() hook, and maybe some other hooks, then maybe you can write your app without accessing the django model layer at all, and delegate all that to your users
frewsxcv_: totally depends on what your app is about, obviously