#django

/

      • fikka has quit
      • apollo13
        well obviously, that is how rows generally look like
      • Fuyou
        better stop wasting you time if you still have something else to learn
      • lordofthekebabs
        well i will have another project
      • if i finish this one
      • Fuyou
        try this: User.objects.filter(followed__user = current_user)
      • lordofthekebabs
        it is the last bit of thing i am having trouble with
      • Fuyou
        I've forgot again, but I think this should work
      • lordofthekebabs
        oh
      • let me try
      • chasonchaffin joined the channel
      • jtiai has quit
      • jtiai joined the channel
      • Fuyou
        see if it gives error
      • lordofthekebabs
        it gave
      • Cannot query "username": Must be "FollowModel" instance.
      • Fuyou
        eh, where did username come from
      • lordofthekebabs
        i did as you said followings = User.objects.filter(follower=current_user)
      • and than tried t print it
      • thats wher eit broke
      • Fuyou
        I wrote very different code
      • lordofthekebabs
        oh the `followed__user ` was intentional ?
      • i taught you forgot the model field name
      • well it gave the same error
      • and the username comes from this line `current_user = get_object_or_404(User, pk=request.user.id)`
      • m-misseri
        pin
      • ping
      • apollo13
        lordofthekebabs: please read the topic and supply the requested information (all of it)
      • Fuyou
        yeah, post your full code now and traceback too better, it's something different probably
      • lordofthekebabs
        alrighty
      • do you mind if i send you the github repo ?
      • Fuyou
        If I confused complex queries again it would complain about not being able to resolve name into field or something like that
      • lordofthekebabs
        or just the view in a dppaste
      • m-misseri has quit
      • Fuyou
        Whatever makes me see the code in acceptable format (irc being not acceptable code formatter)
      • lordofthekebabs
        okay a sec im pushing the code
      • let me paste the tracebaack
      • oblikoamorale joined the channel
      • lordofthekebabs_ joined the channel
      • oblikoamorale has quit
      • lordofthekebabs_
        Fuyou sorry my internet got disconnected for a second
      • oblikoamorale joined the channel
      • lordofthekebabs has quit
      • Fuyou
        damn, those names confuse me, a moment please ^_^"
      • lordofthekebabs_
        Fuyou thats okay thanks a lot for trying to help :)
      • kutenai
        Greetings all. I have a question about best practices, related to the ORM. I teach my development team this is the 'standard style' https://dpaste.de/emvg, but I don't know that I can point to a particular document(s) that define "standard".
      • Fuyou
        I believe your try\except hides the original error, though I think my line was incorrect here
      • Lazerskates has quit
      • nevertheless
      • lordofthekebabs_
        oh my bad
      • Fuyou
        User.objects.filter(followed__follower = current_user) ty this
      • outside of try: preferably
      • lordofthekebabs_
        alright a sec
      • kutenai
        They submitted some code that uses this approach -- Model.object.filter(pk=pk).first().. and I'm like that's not the standard way to do it.. but then, I'd like to be able to point them at some reference for "standard". If anyone knows of a good reference or two along these lines, I'd appreciate the links
      • Papinak joined the channel
      • Papinak
        Hello
      • How django know about '[:5]' in 'Article.objects.all()[:5]'. I thought django will get all articles, and then python slice it. But not. Django add LIMIT 5 to the SQL query.
      • lordofthekebabs_
        oh yes Fuyou it worked
      • Papinak
        How is it possible?
      • lordofthekebabs_
        thank you very much but what is this way much more advanced level of querying that i dont have to worry about for now?
      • i didnt see any of this magic in tutorials
      • apollo13
        Papinak: because you can control what slicing does in python
      • mattmcc
        Papinak: For a given object type, you can customize what [x] does.
      • Papinak
        +apollo13 Oh. thanks.
      • Fuyou
        lordofthekebabs_, it would be a bit more simple if you actually used a many-to-many field, it would simplify a bit. And your related names were not chosen in a best way
      • Papinak
        +apollo13: Can you send me link for that? I can't find it.
      • Fuyou
        lordofthekebabs_, ok, so it returned all followed users?
      • lordofthekebabs_
        yes it did but
      • now how would i user this in the for loop ? in the temp
      • LordVan has quit
      • apollo13
      • Fuyou
        lordofthekebabs_, wait a moment, it was the hardest part, but now we need a finishing step
      • Papinak
        Thank you! :)
      • lordofthekebabs_
        Fuyou alright i am listening
      • Fuyou
        TweetModel.objects.filter(user__in=following)
      • given that following is that var with queryset we got before
      • lordofthekebabs_
        alright im going to name this var `home_feed`
      • a sec
      • Papinak has quit
      • Guest6298 joined the channel
      • Fuyou
        I'd rather name it so it explains what kind of object it contains. But whatever makes sense to you
      • lordofthekebabs_
        well Fuyou it worked but still when i print it it is grouped by the sets
      • it goes like
      • chasonchaffin joined the channel
      • user1 , user1, user1 and user2, user2, uer2
      • fikka joined the channel
      • but it is one queryset which is what i intended
      • Fuyou
        lordofthekebabs_, ok, but now it is single queryset
      • lordofthekebabs_
        yes
      • Fuyou
        you can order_by(...) on it
      • lordofthekebabs_
        oh alright let me try
      • Fuyou
        .order_by('publish_date')
      • nobodi has quit
      • and it only 2 queries instead of how many you did before
      • lordofthekebabs_
        Fuyou :))))) IT works
      • GOD yes thanks a lot
      • Fuyou
        maybe could be brought to one, but I guess 2 should be fine for now
      • lordofthekebabs_
        but still i didnt do anything :P
      • joshbright has quit
      • But thank you alot i was trying to do this for 2-3 hours
      • ahahah have a nice night
      • Fuyou
        lordofthekebabs_, yeah, I'd rather not code for you, but I wasn't quite sure for exact line myself this time
      • kupi joined the channel
      • lordofthekebabs_
        Fuyou well maybe it is just for this time
      • Fuyou
        important part - did you get the idea in step #1?
      • lordofthekebabs_
        but thanks again
      • well yes but you used some magical complex querying
      • which i did not see before
      • Fuyou
        filter(followed__follower = current_user)
      • lordofthekebabs_
        yes
      • Fuyou
        "followed" part here is related_name, see?
      • lordofthekebabs_
        okay i dont even know what related name is doing i just used it since the dj debug gave a hint
      • ooooooooooohhhhhh
      • it just clicked
      • but why not just use filter(follower=current_user)
      • isnt it the same thing
      • why add the related name
      • Fuyou
        it's like "FollowingModel has followed User -that means-> User has number of FollowingModel instances which will be addressed by related_name=followed"
      • lordofthekebabs_
        oh its like a bad many to many trleation ship ?
      • joshbright joined the channel
      • joshbright has quit
      • thats why you were saying use many to many
      • Fuyou
        why bad? As I said what you have implemented is basically a many-to-many. You just didn't use a convenience shortcut which is ManyToManyField
      • lordofthekebabs_
        now i get it
      • again thank you a lot for taking your time to help me
      • have a nice day :)
      • finster joined the channel
      • joshbright joined the channel
      • Fuyou
        so User has 'followed' field, which return queryset of FollowingModel's which you can query on FollowingModel.follower
      • lordofthekebabs_
        now i understand why you said i should name them better
      • nobodi joined the channel
      • Fuyou
        Well, it takes some time to sink in, it did for me at least
      • lordofthekebabs_
        ahah :)
      • jessamynsmith has quit
      • i m gonna quit now but thanks again
      • have a nice day
      • lordofthekebabs_ has quit
      • slav0nic has quit
      • Donitzo joined the channel
      • phiofx has quit
      • phiofx joined the channel
      • pjj has quit
      • pjj joined the channel
      • xpen has quit
      • xpen joined the channel
      • chasonchaffin joined the channel
      • fikka has quit