#django

/

      • andyhoang1 has quit
      • mcspud
        How fair ye' cobba
      • anddam
        moldy: mmm because the db schema could go back and forth in history with migrations, but the python model would stay at the new version, lacking that column
      • andyhoang1 joined the channel
      • moldy
        mcspud: hi :p
      • anddam
        moldy: and I see the django.db.migrations.state.StateApps instance returns a fake model, this is the model you just talked about, the one "historically right"
      • mcspud
        ;)
      • moldy
        yes, i think so
      • anddam
        is that correct?
      • ok
      • moldy
        i never really digged under the hood of migrations, but this is my understanding of the high-level concept
      • mcspud
        yes that is correct
      • anddam
        so in my case the manager is correct, the issue is I cannot call methods of the fake model since only fields are built
      • mcspud
        A migration typically means changing the database state
      • anddam - yep, I move everything to management commands and run them there
      • moldy
        either that, or if you have to call a method, turn it into a function and copy / paste it into your migration file
      • mcspud
        anddam - if the command should only be run once I inspect `django_migrations` and use it as a history log so I cant run it again
      • YMMV though
      • jhfisc has quit
      • anddam
        mcspud: wouldn't you have the same historical correctness issue?
      • massover joined the channel
      • mcspud
        No
      • jhfisc joined the channel
      • anddam
        mcspud: how so?
      • I mean the issue about using a model that doesn't reflect a db schema is still there, even with commands
      • jhfisc has quit
      • haidsidj has quit
      • jtiai^ is now known as jtiai
      • jackhum has quit
      • massover has quit
      • idontneedanick has quit
      • magellanic joined the channel
      • idontneedanick joined the channel
      • bakirelived has quit
      • jhfisc joined the channel
      • Mark_2 has quit
      • bakirelived joined the channel
      • Coffie
        I'm trying to create a user and upload a file which is handled by a userprofile model in the same view. I have a create user modelform and a fileupload modelform which are shown in the same view. The user profile has a onetoone field to a user and when I try to register the user, either I can't get the file to upload or I get an Integrity error because when I am saving the upload form the profile does not
      • have a user. Any tips on how to solve this? I need to be able to create the user and upload the file in the same view.
      • jhfisc has quit
      • jhfisc joined the channel
      • n0ar joined the channel
      • amcorreia joined the channel
      • Lauxley
        Coffie: You have only one html for right ?
      • form*
      • Xorg joined the channel
      • Coffie
        Lauxley: yes
      • jhfisc has quit
      • Lauxley
        Coffie: have the user form save method return the user (i think it should already) and pass it to the save method of the profile ?
      • Coffie
        Lauxley: I have been able to create the profile by doing that, but the file is not uploaded or added to the model
      • Lauxley: it might be my uploadform that's worng, I only have the profile as the model for the form and the only field is the filefield
      • s/worng/wrong/
      • Lauxley
        Coffie: show the code (i will leave soon but somebody will probably help you if you show the view code)
      • Coffie: do you pass request.FILES to the form ?
      • jhfisc joined the channel
      • amcorrei1 joined the channel
      • kingarmadillo joined the channel
      • amcorreia has quit
      • jhfisc has quit
      • massover joined the channel
      • jhfisc joined the channel
      • Coffie
        Lauxley: yes to the file upload form i pass both request.POST and request.FILES, and to the user creation form I pass only request.POST
      • kingarmadillo has quit
      • amcorrei1 has quit
      • kedare joined the channel
      • idontneedanick has quit
      • idontneedanick joined the channel
      • jhfisc has quit
      • jhfisc joined the channel
      • massover has quit
      • idontneedanick has quit
      • Leeds has quit
      • __marco has quit
      • Ahuj has quit
      • idontneedanick joined the channel
      • theology has quit
      • jhfisc has quit
      • Troy joined the channel
      • jhfisc joined the channel
      • lukebigg has quit
      • drodger has quit
      • andyhoang1 has quit
      • Schrostfutz joined the channel
      • bakirelived
        HyP3r: I'm also working with modbus so hey o/
      • kyern has quit
      • kyern joined the channel
      • Schrostfutz
        Hi, I have a general question about django. The apps are supposed to allow for decoupled functionality (?). When creating my apps I have trouble separating functionality from looks. One issue I am facing is this: My app defines views that I use. The templates those should be rendered to however extend my base.html template which results in a cyclic dependency. Is there a way to avoid this?
      • drodger joined the channel
      • Another example is navigation: This needs to be hardcoded in the base template but depends on the urlconf which is used.
      • chaosk joined the channel
      • __marco joined the channel
      • Ahuj joined the channel
      • idontneedanick2 joined the channel
      • idontneedanick has quit
      • damienxx joined the channel
      • RonWhoCares has quit
      • moldy
        Schrostfutz: where do you have the cyclic dependency? i don't understand
      • anddam
        while using pylint within Visual Studio Code I get annoying messages like E1101:Class 'User' has no 'DoesNotExist' member
      • moldy
        tell pylint to ignore that error
      • anddam
        and E1101:Instance of 'User' has no 'service_set' member
      • moldy
        static linters can't be perfect with dynamic languages like python
      • anddam
        ok, but why isn't pylint finding the class attributes?
      • pwrentch joined the channel
      • butteredtoast joined the channel
      • moldy
        probably because they are generated dynamically
      • anddam
        oh I didn't know pylint was a static linter, I thought it tried and import stuff
      • so I guess I don't really need to use pylint from the virtualenv as I did
      • moldy
        it might import stuff, dunno. but some things may happen even after import time
      • anddam
        ok, I asked as I figured there was something well known (to other people, that is) about DoesNotExist and the like
      • I like how he asks Meta class to have more public methods as well
      • I'll check pylint-django package
      • Schrostfutz
        moldy: My app defines some views and should be rendered to some template. If I want that template to use the same look-and-feel as my main application, I extend the base template I use. This introduces a cyclic dependency.
      • The main application uses the apps urls and that way its views, the app uses the base's templates
      • jhfisc has quit
      • jhfisc joined the channel
      • moldy
        Schrostfutz: i don't see a cyclic dependency here
      • {% extends "base.html" %} is not a dependency on your project
      • it only depends on *some* base.html existing, it doesn't care which one or where it's coming from
      • Schrostfutz
        moldy: Well, not explicitly, but it depends on the naming convention of the base template and its blocks. Is there a common way they should be named?
      • moldy
        Schrostfutz: base.html is common
      • Schrostfutz
        moldy: And block names?
      • nulltek joined the channel
      • apollo13
        I usually have base.html and app/base.html so my apps can rewire blocks as needed
      • moldy
        for blocks, "content" is pretty common
      • also, remember that your project can override app templates
      • xbogdan
        Hey guys, what would be the best way to override a django class method ? For example I want to rewrite the models.Field base class, more exactly the cached_col property or the get_col method. I don't want it to cache that for a one of my models.
      • apollo13
        this way even if base.html has block mycontent app/base.html can transfer that to content as needed
      • xbogdan: not supported
      • moldy
        some people hold the opinion that reuseable apps should not ship templates at all, or only minimal example templates
      • (because more often than not, the project ends up overriding the template anyway)
      • xbogdan
        apollo13: i guess i can make my own class that inherits from the Field class and only overrides that desired column
      • amcorreia joined the channel
      • jhfisc has quit
      • but then I have to make a class for each type of field
      • jhfisc joined the channel
      • Tivrusky_IV joined the channel
      • apollo13
        xbogdan: well, it is cached for a reason and also not public api
      • Schrostfutz
        moldy: Okay, I see. What about styling of e.g. form elements? The approaches I have seen to adapt e.g. classes of the generated forms use an adapted ModelForm. Is there a way to do this from the project?
      • apollo13
        so even if you manage to override you probably might break more stuff
      • Tivrusky_IV
        Guys, I have a problem that I do not know how to solve - though I cant imagine why it would be so diffucult.
      • I have a html page with custom forms (using mptt tags)
      • and I want to connect that page to a view
      • So use my own form, with my own fields
      • but I cant get the values to the view
      • apollo13
        xbogdan: and the real question would be: what are you trying to achieve
      • jhfisc has quit
      • xbogdan
        apollo13: I'm trying to implement a transparent way for a model to use a partionned postgresql table, see here my stackoverflow question: https://stackoverflow.com/questions/45354503/po...
      • apollo13
        xbogdan: doesn't postgresql do that transparently nowadays?