#django

/

      • jerojasro
        and the authors end up suggesting that it's better to define several model managers, but take care of declaring always "objects" before any other declarations
      • marcaurele joined the channel
      • I guess the model manager declaration performs some weird attribute/property manipulation on its host class, hence the warning
      • fission6
        i am not convinced its really that bad to call one view from another, can someone convince why it is, it'd prefer this over a redirect
      • how is it any different than calling a function from within another?
      • thaxy
        I still dont get it... I mean I get the warnings from them but could you give this a look? https://dpaste.de/pfo3#L28,45,52
      • XofP has quit
      • jerojasro
        thaxy which warnings?
      • jas02 has quit
      • is django spewing warnings?
      • jas02 joined the channel
      • thaxy
        I mean the warnings from the authors^^ no the code executes fine but I want to understand the warning in the book. I get it that there is a problem with class inheritance and apparently in defining more than one manager
      • so I should stick with ONE custom or default manager. Which means my sample would be valid and good practice?
      • zivester joined the channel
      • jerojasro
        thaxy from what I see in your code, you should be good as long as you don't create additional models that inherit from User
      • thaxy
        u mean by Article?
      • jerojasro
        thaxy yes, my bad. Article
      • silverbaq joined the channel
      • fission6 if you just re-use a view from another view, you would also be calling that view's decorators
      • jas02 has quit
      • maybe just refactor the common part of those views to a function, with no decorators nor whatever, and call that from the two views you have
      • jas02 joined the channel
      • v0lksman
        having trouble with some middleware. If I have flatpages AND redirects installed, if flatpages finds the page, redirects middleware still catches that as a 404. Why is that?
      • jerojasro
        v0lksman maybe the order of the middlewares in the middleware list? (just guessing)
      • sol1x joined the channel
      • ams__ has quit
      • fission6
        jerojasro can the refactored portion return an HTTP Response?
      • seems like it would be fun
      • fine*
      • jerojasro
        fission6 sure why not
      • fission6
        do you have a good place for that kind of code to live, i'd like to pull it out of views.py
      • and pop into_something_else.py
      • v0lksman
        jerojasro: I have flatpages and then redirects but both use similar tricks to render...they both start with if response.status_code != 404
      • so I guess my question is why doesn't flatpages or redirects change the status code when it finds a match?
      • jerojasro
        fission6 I'd just leave that in views.py . Or maybe would create a (base) class based view, and create the two views you need by inheriting ...
      • jas02 has quit
      • fission6
        k
      • i like to avoid CBV unless there is real reuse going on
      • jerojasro
        dunno, depends on the specifics. But I would frown upon code that takes requests, gives out responses, and doesn't live in a views file
      • v0lksman no idea; never used flatpages
      • ionescu77 has quit
      • jas02 joined the channel
      • mojtaba joined the channel
      • thaxy
        I never had so much trouble understanding a topic in the book and I read every page... the authors say "With this knowledge in mind, in your model class,objects = models.Manager() should be defined manually above any custom model manager." So they suggest always manually defining objects = models.Manager() and after that line e.g. published_objects = PublishedManager()?
      • knbk
        v0lksman: they do change the status code if a flatpage or redirects is found. if you have redirects after flatpages, then redirects is run first, since response middleware is run in reverse order
      • seds joined the channel
      • camilo100 has quit
      • roomcayz joined the channel
      • READ10 has quit
      • thaxy: if you define a custom manager, the default `objects` manager won't be added automatically, so typically you define ``objects = models.Manager()`` if your custom manager changes default behaviour (such as filtering out non-published objects)
      • zivester has quit
      • v0lksman
        knbk: reverse?
      • knbk
        v0lksman: in response middleware, the last one in the list is run first
      • zivester joined the channel
      • jerojasro
        v0lksman both redirects and flatpages are listed in the middleware setting in django. Does your problem go away when you swap the order in which they are listed?
      • zub1n has quit
      • mo` joined the channel
      • v0lksman
        knbk: I think that will solve my problem...thanks!
      • jerojasro
        v0lksman (I think) you are welcome :)
      • jas02 has quit
      • jas02 joined the channel
      • thaxy
        jesus that rang the bell
      • thanks
      • energizer has quit
      • mojtaba has quit
      • scruz joined the channel
      • mattmcc joined the channel
      • jas02 has quit
      • scruz
        hi. all of a sudden, my CreateView subclasses all throw an AttributeError on get_success_url()
      • r29v has quit
      • pembo13 has quit
      • mattmcc
        What's the traceback?
      • marcaurele has quit
      • scruz
        according to ccbv.co.uk, BaseCreateView sets self.object to None, and the default implementation of get_success_url() in ModelFormMixin has this line in it executed if self.success_url is set: url = self.success_url.format(**self.object.__dict__)
      • mattmcc: AttributeError: 'NoneType' object has no attribute '__dict__'
      • BaseCreateView sets self.object to None in post()
      • knbk
        it also sets self.object to an instance in form_valid()
      • mattmcc
        ModelFormMixin sets it to the return value of ModelForm.save
      • scruz
        ah. so that's the issue. i'm not using the saved object, just trying to redirect back to the list of items
      • sec^nd has quit
      • sec^nd joined the channel
      • i'll just go back to having an explicit get_success_url
      • thanks
      • mojtaba joined the channel
      • guhcampos joined the channel
      • scruz has quit
      • klow
        heya.. I have views which are included called "login" , "logout" and "logout_then_login" , but when I log out of my site I am directed to the *admin* login page, despite having sett LOGIN_URL and LOGOUT_URL in my global settings and restarting. I followed a tutorial exactly I believe, but it was for 1.8 whereas now I am on 1.11.5 . has there been a change in this?
      • jtiai^_ has quit
      • upon logout I hope to be redirected to the login page of my app at /account not /admin
      • r29v joined the channel
      • stridebird1 joined the channel
      • eperzhand joined the channel
      • energizer joined the channel
      • r29v has quit
      • stridebird has quit
      • stridebird1 is now known as stridebird
      • laerus has quit
      • marlinc has quit
      • Xard has quit
      • epopt joined the channel
      • NM, LOGOUT_URL is removed and LOGOUT_DIRECT_URL is the appropriate setting in 1.10+
      • mojtaba has quit
      • GPenguin has quit
      • tempate joined the channel
      • tempate
        Hello. As stupid as it may sound, I'm having trouble removing django-allauth from my project. I removed everything that had anything to do with it and I'm getting 'No module named allauth'. What should I do? I can't makemigrations because of this issue, and therefore, can't remove it properly
      • ionescu77 joined the channel
      • czart_ joined the channel
      • seds has quit
      • jerojasro
        tempate what's the stacktrace? it should tell you where it is being imported
      • tempate
        jerojasro: I'm an idiot and I hadn't deleted the url
      • thanks and sorry
      • jerojasro
        tempate a self-correcting idiot. Welcome to the club, and don't be sorry :)
      • tempate
        alright, thanks
      • ionescu77 has quit
      • seds joined the channel
      • govg has quit