#django

/

      • Kangermu
        lordofthekebabs: i've done them before and they definitely help starting, but in general I find picking a project and making yourself do it is probably the best way...i tend to lose motivation with online courses
      • fission6: might need to do 2 step migration...making the field, copying values over and then removing the original
      • fission6: which isn't exactly seamless, but its very doable
      • lordofthekebabs
        Kangremu alright last question i know im taking a lot of your time :) do you tend to jump from project to project or do you usually obsses over one project and make it really good
      • lllama
        So I have a queryset that is a few .union()s that each contain a few annotations. I'd like to pull a value from that QS to use in an exclude filter, but I'm getting "subquery has too many columns" as an error, regardless of what I pass to .values_list
      • fission6
        Kangermu looks like i could directly migrate!
      • lllama
        any ideas?
      • Kangermu
        i definitely obsess over one...I'd rather have one really nice project on my github that I can show than have 15 half done projects
      • pwood22 joined the channel
      • lordofthekebabs
        Kangremu alright it seems like im doing every step wrong aahahha, bt thank you very much tho
      • Kangermu
        fission6: haha...nice....i didn't think you'd be able to for some reason (even though theres no real reason they can't just stringify the int)
      • lordofthekebabs
        can you link your github
      • Kangermu
        which is what I assume it does
      • lordofthekebabs
        i would love to check it ouy
      • Kangermu
        lordofthekebabs: haha...i've long since deleted my public stuff, sorry :P
      • lordofthekebabs
        whaat
      • Kangermu
        but stuff like todo apps are easy enough
      • lordofthekebabs
        well i have already cloned twitter
      • and it works actually good
      • just want to advance myself
      • pwood22 has quit
      • thanks a lot for tthe advices
      • take_flight joined the channel
      • Kangermu
        not a problem
      • fission6: which django version are you running?
      • lordofthekebabs has quit
      • kanja joined the channel
      • stitched_unicorn joined the channel
      • hpanago joined the channel
      • pwood22 joined the channel
      • pwood22 has quit
      • nobodi has quit
      • sturtle joined the channel
      • VikingHoarder joined the channel
      • take_flight has quit
      • thiras has quit
      • jwhitmore has quit
      • ovalseven8 has quit
      • folksilva joined the channel
      • Kangermu has quit
      • safwan joined the channel
      • joshbright has quit
      • fission6
        1.11.12
      • Leeds has quit
      • Nizumzen joined the channel
      • pwood22 joined the channel
      • Ryanar
        Has anyone experienced issue with DRF API Permissions? I am having issues because I want to compose my permissions, e.g. IsAuthor, IsAdmin, and if either passes they have access to the view, but DRF makes it so if any permission fails they are unauthorized
      • omarramo joined the channel
      • because of this I have to keep re-writing the same permissions logic over and over again
      • I have a few other roles, so for instance: IsAuthor or IsManager or IsStaff or IsAdmin and the permissions on an endpoint might be any combination of the above
      • pwood22 has quit
      • omarramo
        hey guys. I have a model with a foreign key field. I want the user of the API, when creating, to supply the model without that foreignkey field. when creating a new instance for that field should be created.
      • Ryanar
        and then I have issues when I want to do things like, only the Author/Admin can put/patch, (has_object_permissions method) but I want Managers/Staff to be able to retrieve it
      • pwood22 joined the channel
      • omarramo make the FK nullable if you want to create the model without it
      • sunil_bansal joined the channel
      • sunil_bansal has quit
      • sunil_bansal joined the channel
      • if you are using `drf` you can override the view method's `perform_create` to tack on the FK on save, or you could do it in the serializer, or you could override the model's save method
      • omarramo
        Ryanar, I did it in the serializer but it somehow doesnt apply for the fixtures
      • for the fixture models its still null
      • Debnet has quit
      • and in the admin interface that field is still required somehow
      • lacrymology joined the channel
      • sunil_bansal has quit
      • Ryanar
        well your fixtures aren't using your Serializer
      • so of course that doesnt work
      • fixtures are kinda terrible
      • omarramo
        ah I see
      • pwood22 has quit
      • GraysonBriggs has quit
      • Ryanar
        better to use FactoryBoy / Faker libs to generate factories to produce model instances with fake data
      • totte joined the channel
      • sunil_bansal joined the channel
      • re1 joined the channel
      • unless you are talking about pytest fixtures?
      • pwood22 joined the channel
      • omarramo
        and about the admin interface thing? how can I get the form where I have to select an instance of the referenced object to disappear?
      • Im using the normal fixtures but thats not a big problem. ill just assign it when I need it for now
      • jessamynsmith has quit
      • Ryanar
        the admin interface pulls automatically from your model, so if it is required in the admin, it is required on the model
      • you need to have `user = models.ForeignKey('User', null=True)`
      • if you want to be able to create the model without a FK reference
      • omarramo
        weird
      • crs
        Ah, no matter what I do can't figure out how to remove BLANK_CHOICE_DASH from ordering select within django-filter…
      • Ryanar
        if you have that and it is still showing, you are overriding or supplying a custom form to the Admin site model that is requiring the field
      • not really weird, without that `null=True` you are saying this model has a foreign key constraint on another model that is not nullable, so it must always have that relationship
      • knbk
        null=True makes it nullable in the db, blank=True makes it not required in modelforms/admin
      • Ryanar
        true, I forgot about that! thanks knbk
      • stitched_unicorn has quit
      • netheranthem joined the channel
      • omarramo
        when I create a model from the admin interface, the modelserializer's create() method will be called, right?
      • re1_ joined the channel
      • knbk
        no, the admin uses ModelForms, it doesn't use your serializer
      • Ryanar
        you are confusing django with django-rest-framework
      • omarramo
        ah ok
      • yeah Im just hacking things together right now, I have no idea about any of this
      • but its going ok so far
      • Ryanar
        serializers are an abstraction introduce by django-rest-framework to deal with serializing/unserializing django models
      • and used by its APIView, and generic views/viewsets
      • you should be making a model form if you want a custom form for your django admin
      • omarramo
        where does this normally go? as in which file
      • Ryanar
        and I use django-easy-select2 to quickly bake in searchable foreign keys
      • `<project>/<appname>/forms.py`
      • so if you have an app called `polls` it would be `polls/forms.py`
      • Django should make a `forms.py` if you use it's start app functionality
      • jessamynsmith joined the channel
      • Druid05 joined the channel
      • pwood22 has quit
      • arlyon has quit
      • arlyon joined the channel
      • omarramo
        Ryanar, I defined a modelform with less fields, how do I apply that to the admin interface?
      • Ryanar
        add a class variable `form = MyForm`
      • class PollAdmin(admin.ModelAdmin):
      • form = MyPollForm
      • jj7 has quit
      • pwood22 joined the channel
      • arlyon has quit
      • arlyon joined the channel
      • jj7 joined the channel
      • omarramo
        now it somehow cant find my model
      • i am importing models and in the modelform it says model = models.MyModel
      • IDE autocompletes it and everything
      • re1_ has quit
      • error message says apps.app.models has no attribute 'MyModel'
      • re1 joined the channel
      • Ryanar
        would need to see the code
      • sturtle has quit
      • nobodi joined the channel
      • amirpro has quit
      • kanja has quit
      • lavalamp joined the channel
      • lacrymology
        I'm getting a CSRF error when trying to go to the admin, can someone help me debug it?
      • xliiv joined the channel
      • Kangermu joined the channel
      • apollo13
        lacrymology: depends, if that is all the information you have to offer, then no :þ
      • lacrymology
        I'm making a deploy, it works fine in dev, but it's not working in deploy (i've got dev->deploy->stage->prod
      • Doow joined the channel
      • apollo13: I don't know what else can help
      • I.. think I don't see the cookie being sent
      • apollo13
        lacrymology: well for starters, which error do you get?
      • lacrymology
        on the POST
      • CSRF missing
      • Ryanar
        is the CSRF token there in your browser?
      • if not you aren't including it
      • might be the middleware isn't being added in production
      • mirk0 joined the channel
      • apollo13
        lacrymology: the exact error please
      • lacrymology
        Ryanar: The cookie is being set on the GET, but the post doesn't seem to be sending it back, AFAICS
      • apollo13: CSRF verification failed. Request aborted.