If have a User model and a mapping table that maps owners to resources. How do I get all users that have a row in that mapping table? Totally trivial in SQL but what is the django ORM syntax for that query?
so it's really just a many-to-many through table you've made explicit for no apprciable reason
cnk
right
FunkyBob
User.objects.filter(resourceowner__isnull=False)
cnk
Thank you!
kenbolton joined the channel
I was trying to start from ResourceOwner and getting nowhere. But the user query should be great. Thanks
FunkyBob
if you want Users, you start at User
pantsofchocolate has quit
keimlink_ has quit
BabySuperman joined the channel
ASonOfGod has quit
thinkt4nk joined the channel
darylantony joined the channel
Nizumzen joined the channel
ycon_ has quit
Azelphur
mattmcc: re earlier question, if not form.field.errors returns true if the form was never submitted before
mattmcc
Sure, because there aren't any errors.
SimNim has quit
Azelphur
mattmcc: yea, I was after only returning true if the form was already submitted
KaffeeJunky123 has quit
ie you already submitted the form, and this field is good, but this field is bad
avatarez joined the channel
mattmcc
Ah, testing form.data might suffice.
For 'has been submitted'
a_little_birdie
So here I am changing all my explicit uses of '/static/' and '/media/' and I come across a place where in some admin modelforms I have a class Media defined with some js and css in it, and these are full paths.
thinkt4nk has quit
Azelphur
mattmcc: hmm, what is form.data? having trouble finding docs on it
Leeds joined the channel
BabySuperman has quit
ASonOfGod joined the channel
asbjxrn has quit
FunkyBob
a_little_birdie: which, iirc, if relative will be resolved through static
a_little_birdie
So the question is, is there an elegant way to avoid saying '/static/app/js/jquery.js' for example, in the Media: js = {
kenbolton has quit
superdupernoob
a_little_birdie all the media and static stuff should be relative
a_little_birdie
Ahh that is the kind of answer I was hoping for :)
and you should just have one setting in the settings.py file
a_little_birdie
Lemme try it!
superdupernoob
then in templates there's a {% static %} tag
Azelphur
mattmcc: thanks :)
jmckind has quit
a_little_birdie
yep perfect, awesome thanks
thinkt4nk joined the channel
ujjain joined the channel
WeiJunLi has quit
superdupernoob yea I am using the static tag, actually that is what I am doing today is cleaning up a situation where everything was in media and I am moving what should be static into static
superdupernoob
coolio
a_little_birdie
But in the transitional phase I have them defined the same
nimomo joined the channel
I actually discovered today that I was serving a lot of files through django that did not need to be served through django
superdupernoob
I did the opposite today. I started serving all my static files through django because I didn't want to go crazy with my docker setup
mattmcc
superdupernoob: Check out whitenoise
a_little_birdie
Yea I have it set up so that if nginx intercepts the request then great, but if it does not then django will serve it.
chachan has quit
This all came about because I decided to implement a dynamic thumbnailer with a cache instead of pregenerating thumbnails.
thinkt4nk has quit
superdupernoob
mattmcc I just added urlpatterns += staticfiles_urlpatterns() to my urls.py
ehmatthes joined the channel
a_little_birdie
Which works great, now I can serve whatever size I need on demand.
superdupernoob
whitenoise is going to be better than that?
nimomo has quit
a_little_birdie
But now we are storing images and files in the database, so ya.. django will serve everything under /media/ . There will be a cache of course.
superdupernoob
matrmcc I'm having issues with whitenoise
it saying I need to set the DJANGO_SETTINGS_MODULE env variable, but I'm doing that the line before
I just needed to move the import statement below that line.
Thanks for pointing out whitenoise to me
timkofu has quit
Lobstaman3 has quit
pantsofchocolate joined the channel
timkofu joined the channel
brockhaywood joined the channel
SecondForm_Glenn joined the channel
sargas has quit
t0mb0 joined the channel
elyezer joined the channel
ehmatthes has quit
Audioburn has quit
infecto has quit
Bryson has quit
ybathia has quit
brockhaywood has quit
lorddaedra joined the channel
Andy80 joined the channel
superdupernoob has quit
brockhaywood joined the channel
superdupernoob joined the channel
rpkilby has quit
lorddaedra has quit
Quitta has quit
robbyoconnor joined the channel
robbyoconnor has quit
Quitta joined the channel
mrhanky has quit
mrhanky joined the channel
crakrjak joined the channel
Quitta has quit
garrypolley joined the channel
msc has quit
_ritchie_ has quit
darylantony has quit
sef has quit
sef joined the channel
SimNim joined the channel
SimNim has quit
darylantony joined the channel
hey everyone, I have a search form that runs a GET request and returns on the same page. How can I have the form auto-populate the same entries when it refreshes?
FunkyBob
superdupernoob: same way as you normally do... render it from the Form instance you used to process the submission
cnk has quit
superdupernoob
so I might select a category and hit "Filter" (submit) and I when it comes back I want that category already selected in the form so I can enter a price range
jeremytiki has quit
Audioburn joined the channel
SimNim joined the channel
FunkyBob what do you mean?
FunkyBob
are you using a Form class to validate the user input?
Ariel_Calzada joined the channel
nimomo joined the channel
/win 6
blah
mattmcc
So use request.GET instead of request.POST as the bound data for the form.
superdupernoob
I am using a form class, yes
FunkyBob
superdupernoob: perhaps if we knew what your actual code was...
superdupernoob
one sec
FunkyBob
are you passing the Form class to the template, and rendering the form inputs from it?