#django

/

      • phildini
        avidal: cool.
      • jake1016 has quit
      • mstrcnvs has quit
      • fllr has quit
      • avidal
      • fllr joined the channel
      • create a User model in an 'auth' package that subclasses AbstractBaseUser, and the actual User model becomes a django.contrib.auth.models.User
      • with all of the attributes that hang off of it
      • zapo has quit
      • change the package name to something else, eg authz, and that's no longer the case
      • thesheff17 joined the channel
      • same with changing the name from User to Whatever, or not subclassing AbstractBaseUser
      • tbaxter
        Well, kind of. Most times you don't want to subclass abstractBaseUser. Most people want AbstractUser, I'm convinced.
      • faldridge has quit
      • Also, gotta make sure the user_model setting is set.
      • avidal
        Right, but that's all besides the point
      • amigo has quit
      • zapo joined the channel
      • zapo has quit
      • The point here is that creating a model called User that subclasses AbstractBaseUser, within an auth package, replaces the "User" class with "django.contrib.auth.models.User"
      • and i have no idea why
      • willingc joined the channel
      • Gwildorix has quit
      • fllr has quit
      • tm8522010 joined the channel
      • gazumps has quit
      • mattmcc
        avidal: Because of how app names work, you can 't have two with the same name. So don't make an app called 'auth'.
      • rbanffy joined the channel
      • dangayle joined the channel
      • gazumps joined the channel
      • avidal
        I don't even have django.contrib.auth in INSTALLED_APPS, nor is this 'project.auth' package in there
      • georgeirwin
        can anyone tell me how to access the view name from view_func in process_view (middleware)?
      • carljm
        avidal: What Django version?
      • Gwildorix joined the channel
      • avidal
        1.6.1
      • carljm
        avidal: The bug that you're reporting re the User model sounds accurate to me; I think you'll find the behavior in 1.7 (master) more sane.
      • The app-loading infrastructure has been mostly rewritten, and is stricter about installed vs not-installed apps.
      • avidal
        carljm: Is the recommendation to use a different model name or a different package name?
      • armicron has quit
      • carljm
        avidal: A different package name. I often use e.g. "users" or "accounts".
      • avidal
        (I had a feeling it was related the app loader, although it's very curious behavior anyway)
      • neruson is now known as zz_neruson
      • thesheff17 has quit
      • carljm
        Basically in Django pre-1.7 the app cache stores info about any app whose models are ever imported, regardless of whether they are installed or not.
      • So you can have clashes with a contrib app label even if it is not in INSTALLED_APPS.
      • avidal
      • Ah, I see
      • zz_neruson is now known as neruson
      • bogeyd6 has quit
      • Ariel_Calzada joined the channel
      • carljm
        If anything imports those models; and some things in Django internally are not careful about what they import (for instance, the test client causes an import of stuff from contrib.auth, to support its login/logout methods). Though a lot of that has been cleaned up in master, too.
      • avidal
        It's just curious, because the very act of constructing the class and then importing it in ipython, causes it to be replaced
      • carljm
        avidal: right, it's very bad behavior which was introduced for bad reasons: you can find the explanation in ModelBase.__new__
      • avidal
        Well I suppose it's not just importing in ipython, because I'm importing it through manage.py shell
      • cewing has quit
      • stahl joined the channel
      • carljm
        (well, not really the explanation of _why_ it was introduced; but you can find the code that does it there)
      • it was introduced because Django pre-1.4 had a default project setup that tended to cause doubled import paths (where the same Python module could be imported by two different names, e.g. "myproject.myapp" and "myapp"
      • and so people sometimes would end up with two copies of the same Model class
      • myproject.myapp.models.MyModel and myapp.models.MyModel
      • which caused all kinds of exciting problems
      • avidal
        :)
      • carljm
        so the "fix" that was put in place, back in the mists of time, was to have the Model metaclass (ModelBase) always return a cached model class from the app cache, rather than actually creating a new model class, if it found a match
      • and that behavior is what explains what you are seeing
      • cewing joined the channel
      • rozap_ joined the channel
      • Fortunately this bad behavior has also been removed in master / 1.7.
      • avidal
        Ah, right. The thing that was tripping me up was it seemed like it was being replaced in locals(), but instead it's actually because the ModelBase metaclass constructor (__new__) which is responsible for actual model class construction, was, instead of creating my new User class, returning the cached auth.User class which was already imported when I imported AbstractBaseUser
      • carljm
        precisely.
      • because the app label ("auth") and the class name ("User") matched.
      • stickperson has quit
      • and contrib.auth.models was getting imported before your module.
      • HowardwLo joined the channel
      • Oh, what a tangled web we weave, when first we practice evil metaclass tricks.
      • avidal
        :)
      • stickperson joined the channel
      • Yeah, I've touched on metaclasses before, but I completely skipped on the fact that the __new__ method is responsible for returning the newly constructed class, and it can return whatever it wants
      • windyhouser joined the channel
      • carljm
        Yep, we can do all kinds of awful things by taking advantage of that.
      • avidal
        Haha
      • I used it to enforce some interfaces
      • radimnov has quit
      • jontec has quit
      • paddyforan has left the channel
      • codeinthehole joined the channel
      • thesheff17 joined the channel
      • RGamma has quit
      • smoothify has quit
      • smoothify joined the channel
      • natea has quit
      • dfunckt has quit
      • estebistec joined the channel
      • MightyPyro has quit
      • stahl has quit
      • kracekumar has quit
      • EstebanVelour joined the channel
      • knite joined the channel
      • cottons has quit
      • diphtherial
        hey, i'd like to stop using the django test server and start using nginx to proxy to gunicorn or something and also serve the static content separately
      • mariusp has quit
      • do i have to use collect-static every time i make a change to the static files, or is there some way to have that occur automatically?
      • Gwildorix
        So guys, I wrote a nice piece of code for myself which introduced an easy to use functionality on the ModelAdmin, and was pretty helpful to me. It makes it possible to set a widgets dictionary on the ModelAdmin which return widgets for fields, like on a Form. I know formfield_overrides already does that, but that was not scallable enough for me and uses db_fields instead of field names. Now I'm wondering if I should start a discussion about
      • it somewhere so something similar might land in Django. Should I start a topic on the django-developers mailing list or something? It's not that clear to me where the appropiate place is for presenting something like that
      • estebistec has quit
      • AntelopeSalad
        still stuck with uwsgi, has anyone ever seen a "relative imports require the package arg" error thrown by uwsgi? https://gist.github.com/AntelopeSalad/8742598
      • cottons joined the channel
      • Synthead joined the channel
      • mattmcc
        AntelopeSalad: What is ROOT_URLCONF set to?
      • AntelopeSalad
        btw for the record, if i run the server with runserver i can access that url without issues
      • Synthead
        if I have an {% if ... %} bit and want to break it up into multiple lines before the closing %}, how would I do that?
      • cottons_ joined the channel
      • At the moment, I get a syntax error for the endif if I put the "if" in two lines
      • mattmcc
        Oh, it's only a certain URL? Okay, then can you paste your urls.py?
      • AntelopeSalad
        mattmcc: ROOT_URLCONF = '{0}.urls'.format(PROJECT_NAME)
      • well, it's the only url in my app for the most part
      • it's only when i try to access any page with uwsgi too, runserver works for everything
      • estebistec joined the channel
      • josePhoenix
        Synthead: sounds like you're putting too much in that if :)
      • mattmcc
        Synthead: The template parser doesn't support that.
      • diphtherial
        Synthead: if you find your logic is getting that complicated, it might not be a bad idea to compute it in your view...
      • josePhoenix
        Synthead: can you move it to a model method?
      • diphtherial
        right, yes
      • napper joined the channel
      • diphtherial is a bit slow on the draw
      • TiagoTT has quit
      • skaflem has quit
      • cottons has quit
      • elyezer joined the channel
      • patrick91 joined the channel
      • garrypol_ joined the channel
      • mattblack123
        anyone who works with celery?
      • seanbrant
        mattblack123: sure, whats up?
      • nedbat has quit
      • yomilk joined the channel
      • nedbat joined the channel
      • mwmnj has quit
      • Mechanimal joined the channel
      • mattblack123
        seanbrant I followed the tutorial and if I use runserver I can get celery to work, but when I start into the prod env (gunicorn+nginx) I got the following error: ImportError: Could not import settings 'dunning_cruncher.settings' (Is it on sys.path? Is there an import error in the settings file?): cannot import name Celery
      • garrypol_ has quit
      • seanbrant
        mattblack123: do you have a celery.py file in the root of your project?
      • yomilk has quit
      • mattblack123
        yes, I created celery.py, modified __init__,py and created tasks.py
      • NBhosting has quit
      • AntelopeSalad
        mattmcc: is there anything else i can supply to the gist to help fix the situation?
      • mattmcc
        AntelopeSalad: Your urls.py?
      • seanbrant
        mattblack123: do you have "from __future__ import absolute_import" at the top of your celery.py?
      • mattblack123
        yes, I'll paste you in a sec celery.py
      • AntelopeSalad
        mattmcc: for the app or the project?
      • mattmcc
        AntelopeSalad: Both.
      • mattblack123