#django

/

      • cool_dude
        one is by react ( facebook ) community and other is by django
      • Kangermu
        cool_dude: thats an entirely different question :P
      • realnot
        guys, if I want to use a custom manager everywhere? for example filtering by user objects.filter(user=request.user) and only if the user is superuser use the classic objects.all()
      • kanja has quit
      • I mean, when I use objects.all() this should filter by user. Instead if I user superobjects.all() this is not filtered
      • It's a bad idea?
      • sackrebutz has quit
      • kezabelle
        well, without using a threadlocal for request, you have to pass the request along somehow
      • chocoelho joined the channel
      • cool_dude
        yes Kangermu you are right
      • realnot
        yeah, the dubt now is not about retrieving the `request`, I used request.user as example. I just want to swtich this logic
      • obects.all() is a queryset always filtered by `domain` for example
      • superobjects.all() is not filtered by domain
      • kezabelle
        ... you still need to pass the value in somehow.
      • realnot
        what about creating a mixin that define a manager?
      • Ryanar joined the channel
      • vnbang2003 has quit
      • kezabelle: you mean the filter?
      • sackrebutz joined the channel
      • krawchyk joined the channel
      • kezabelle: this way https://dpaste.de/K5ep
      • brundleticks joined the channel
      • Diemuzi joined the channel
      • zhalla_ joined the channel
      • geekodou108 has quit
      • lorddaedra joined the channel
      • Nizumzen joined the channel
      • zhalla_ has quit
      • felixx has quit
      • geekodour08 joined the channel
      • BigJono joined the channel
      • cool_dude joined the channel
      • diek joined the channel
      • omarek joined the channel
      • BigJono has quit
      • sackrebutz has quit
      • kuter has quit
      • gugah joined the channel
      • julipels_ joined the channel
      • KeyJoo has quit
      • Staunch has quit
      • Staunch joined the channel
      • szicari_ joined the channel
      • vimes joined the channel
      • mibiir joined the channel
      • c17r joined the channel
      • vimes
        Hello! I've deployed a django app using Gunicorn and Nginx, but I can't access the django admin page, even though I create a superuser (and have run migrations), it just says username and password is wrong. even though I've created multiple superusers to test. Any idea where the problem might be? I can post any config you guys want, but not sure what you want
      • kanja joined the channel
      • fleetfox
        are you sure web application and cli is accessing same database?
      • porfiriopaiz has quit
      • knbk
        vimes: is the user active?
      • fleetfox
        createsuperuser creates active user
      • assuming you have not messed with it or usermodel
      • vimes
        knbk: I would assume so, I did the same process on localhost and it worked ifne
      • no I have not
      • I did use certbot's nginx package to generate ssl for https though
      • ssv
        try manage.py shell and get all user form auth model
      • Xaldafax joined the channel
      • redir has quit
      • chasonchaffin joined the channel
      • vimes
        the users seem to be there ssv https://dpaste.de/F2dr
      • gugah has quit
      • knbk
        vimes: are user.username and user.password as expected (i.e. user.password is a password hash)?
      • (and I'd check user.is_active just to be sure, even if the default is True)
      • fleetfox
        ar you using sqlite?
      • iamriel
        Hi guys, I am developing an api for a mobile app using django rest, my problem is the mobile team wants us to support passing of "id" to a resource, that means they are the ones who will create the ID/primary key of the model, is it okay to support that one? we are using uuid for the id btw
      • giarc joined the channel
      • chasonchaffin has quit
      • vimes
        not quite sure how to check that, let me google knbk , fleetfox I'm using postgres
      • knbk
        vimes: what exactly are you not sure about?
      • ssv
        vimes: ok, is there user which you created? if yes, probably you need to check your settings.py
      • vimes
        knbk: how to see if passwords are hashed, but I have not fiddled with how django should store passwords
      • ssv: yes the users I created are there
      • ssv
        vimes: try to use a sqlite3 as a default database and also set your SECRET_KEY as a 'abcd' and try to create user again
      • knbk
        vimes: well, if user.password is a plaintext password it is not hashed, otherwise it probably is
      • ssv: huh, why exactly?
      • ssv
        vimes: what version of django you use?
      • knbk
        vimes: also check user.has_usable_password()
      • vimes
        knbk: you misunderstand the true level of my incompetence, I'm unsure how to get user.password (andreas.password). I tried importing * from django.contrib.auth.model and calling andreas.password with no luck
      • 1.11 knbk
      • seemed like the sensible version to use
      • knbk
        vimes: right. You know how to get a queryset, right? you can get a specific user by using `user = User.objects.get(username='andreas')`
      • ssv
        knbk: I'm not sure, maybe he's create a user with one secret key then change it and try to log in :)
      • knbk
        then you can print user.password, etc.
      • colegatron has quit
      • ssv: the secret key has no effect on whether you can log in
      • ssv
        knbk: I mean, when you create a new password
      • knbk
        it's used for password reset tokens and to sign cookies, but that doesn't matter in this case
      • vimes
        knbk: yes the password is a hash
      • I do have a differnet settings file for the server and localhost, but I don't see how it should mess things up
      • knbk
        vimes: does `user.check_password('your_password')` return True?
      • redir joined the channel
      • vimes
        knbk: yes it returns true
      • detseg joined the channel
      • ssv
        knbk: you're right, my bad (only for sessions, messages and password reset token).
      • vimes
        https://dpaste.de/YFhD settings for my production
      • knbk
        vimes: are you using those settings when running the shell?
      • vimes
        hmmm maybe I'm not
      • lobo_d_b has quit
      • export DJANGO_SETTINGS_MODULE=mysite.settings <- this should do it?
      • knbk
        if those are your production settings, yes
      • you can always do `from django.conf import settings; print(settings.DATABASES)` to check if it's what you expect
      • electromonkey has quit
      • GraysonBriggs joined the channel
      • Ahuj has quit
      • jonesnc joined the channel
      • ssv
        vimes: what kind SESSION_ENGINE you use?
      • vimes
        well it works fine when running from the server using just the django server (I know it's a bad idea), still working on making the other settings work
      • ssv
        vimes: probably you session are not save after log in
      • knbk
        iamriel: if you're using the full uuid, you have practically no chance of collisions, so that aspect shouldn't be an issue
      • vimes
        ssv: is this hit? 'django.contrib.sessions.middleware.SessionMiddleware',
      • knbk
        ssv: that wouldn't explain the error message, though
      • davidjackson joined the channel
      • ssv
        vimes: try to check you session store.
      • vimes: no, by default it's backends.db, check you django_sessions
      • iamriel
        knbk: but we still need to verify it in the server right?
      • knbk
        vimes: I think fleetfox was correct the first time and you shouldn't have listened to any of us :)
      • iamriel
        knbk: That means we need to check if there is "really no" conflict?
      • knbk
        vimes: check your server configuration to see which settings file is used by nginx/gunicorn
      • kezabelle has quit
      • vimes
        knbk: it's the production settings file
      • so it stores to postgres, localhost stores to sqlite
      • knbk
        iamriel: for all practical purposes -- no
      • ssv
        vimes: logins are working on the production? but not working on a local enviroment, right?
      • vimes
        no the other way around
      • they are working localhost
      • but not on the server (production)
      • settings file is defined in gunicorn as DJANGO_SETTINGS_MODULE=fossekall.settings.production
      • knbk
        vimes: then run your shell with `--settings=fossekall.settings.production` and check if the user exists
      • ironbeard joined the channel
      • pachewise joined the channel
      • ssv
        vimes: try to connect to postgres and check django_sessions table, the are store any sessions?
      • knbk
        ssv: the login form itself gives an error, so sessions are not the problem
      • vimes
        it seems like it can't find my user now
      • iNCoNFuN joined the channel
      • knbk
        so your shell was using a different database. You need to create the user while using the production settings file
      • ssv
        knbk: hm, maybe need to check AUTH_USER_MODEL and set if it not default.
      • sounds like very strange.
      • khomesh has quit
      • vimes
        knbk: so it seems. can I set it to use the prod. database, or do I always have to manually go into shell with the correct settings defined?
      • I figured it out! I just create superuesr with the --settings. Thank you !!!!
      • ssv
        oh, yay!
      • gz
      • fleetfox
        is there an easy way to swtich default databases at runtime?
      • jadajada joined the channel
      • iamriel
        knbk: I see, thanks :D
      • jpg has quit
      • ironbeard
        Is there any performance difference between setting a model's __str__ to something like '{}: {}'.format(self.region, self.year) vs having a 'name' field on the model that is set to the same string once and then saved? With the name field, then I would set __str__ to self.name. Particularly if an instance's 'name' is dependent on many fields and ForeignKeys of the instance.
      • fleetfox
        depends how often you render and need it