#django

/

      • kiloreux joined the channel
      • kiloreux_ joined the channel
      • maks25 joined the channel
      • entrop joined the channel
      • Leeds joined the channel
      • BPL has quit
      • kiloreux has quit
      • JustASlacker joined the channel
      • maks25 has quit
      • Guddu has quit
      • dg_vrani joined the channel
      • baconbeckons has quit
      • zmt00 joined the channel
      • jongar joined the channel
      • jongar
        How Django is managing the CSRF with a single field while supporting multiple forms?
      • zeus1 joined the channel
      • jessamynsmith has quit
      • jongar has quit
      • JustASlacker has quit
      • ASUchander joined the channel
      • Slaiyer has quit
      • electricbear
        ASUchander, app?
      • ASUchander
        huh?
      • Arizona State electricbear .
      • ASUchander assumed electricbear was asking about App state...?
      • coderphive joined the channel
      • jessamynsmith joined the channel
      • electricbear
        yea
      • NC ip
      • sunil_bansal joined the channel
      • jessamynsmith has quit
      • sunil_bansal has quit
      • beginnerstest joined the channel
      • amirpro joined the channel
      • beginnertest has quit
      • zeus1 has quit
      • PaulWay[w] joined the channel
      • PaulWay[w]
        Morning :-)
      • I'm making changes to my models, so that e.g. where before I stored a book's author as a string, now I have an Author model and the book's author is a foreign key.
      • I think I need to write the migration to create the related Author object for each book.
      • How much of this does Django's makemigration system cover?
      • theWhisper_ joined the channel
      • audioburn
      • PaulWay[w]
        Please don't crosspost :-)
      • nimbiotics joined the channel
      • audioburn has quit
      • nimbiotics
        Hello everyone. I'm running some functionaltest that call an external API that uses a callback function at a certain port. How can I change the testing server port while running tests??
      • PaulWay[w]
        How are you setting the port now?
      • Or is this via runserver?
      • olto has quit
      • nimbiotics
        while running test server I can indcate the port, but not while running python manage test such.such, for exdample
      • converge has quit
      • ldl joined the channel
      • theWhisper_
        okay i have a hard question
      • i have employees model and departments table now each employee can have multiple departments and departments can ave multiple employees. So question is how i can make a query which will show all the employees that share same department?
      • Slaiyer joined the channel
      • beginnerstest has quit
      • beginnertest joined the channel
      • JustASlacker joined the channel
      • schinckel
        theWhisper_: So you have an employee, and you want all other employees who have a reference to the same department?
      • Slaiyer has quit
      • theWhisper_
        yes
      • schinckel
        To any of that employee's departments?
      • theWhisper_
        what you mean to any?
      • jezeniel joined the channel
      • i want to show the user all his coworkers in the x department
      • schinckel
        So an employee has multiple departments, and you want all employees who have _any_ departments in common?
      • theWhisper_
        yes
      • any or all
      • schinckel
        Well, any is a superset of all, so that's all good.
      • theWhisper_
        so how i set this up in my model?
      • schinckel
        You can do a ManyToManyField
      • theWhisper_
        departments has a many tomany relation to employee?
      • schinckel
        Yeah, it doesn't matter which model it's on - django will create a new table (and sort-of-hidden model) to handle it.
      • Then you can go:
      • theWhisper_
        but i dont have a relation set in the employee table
      • schinckel
        Employee.objects.filter(departments=employee.departments.all()) or something.
      • No, you don't need one - django will put a reverse relation in for you.
      • FunkyBob
      • theWhisper_
        so the only field i need setting a relation is in departments saying manytomany with employees?
      • schinckel
        Yeah.
      • razwelles joined the channel
      • l0rd_Qu4s joined the channel
      • theWhisper_
        okay but still i dont get something
      • schinckel
        If you need to annotate those employees with which departments they have in common with employee X, then you can also do that, but it's a bit more work.
      • theWhisper_
        but where do i save it
      • so weird because i have a list of departments
      • schinckel
        What do you mean? How you add an employee to a department?
      • theWhisper_
        no no
      • i have a list of departments in the database which i will use to populate a dropdown field
      • quasimoto has quit
      • this list has department name and code
      • then i have empoyee model which has name
      • the department database must have a manytomany relation to employee?
      • but is going to be empty
      • the manytomanyfield
      • irisarce joined the channel
      • and django will complain
      • no?
      • ldl has quit
      • andyhoang1 has quit
      • nimbiotics
        Hello world! I'm running some functional tests that call an external API. This API expects a callback URL at an specific port. I know the runserver command uses the addrport option but, How can I indicate a port while using test command??
      • theWhisper_
        schinckel:
      • vdamewood joined the channel
      • schinckel: i still don tunderstand
      • zeus1 joined the channel
      • schinckel: because in your example you filter employee using department but in my employee model i dont have a field called department
      • FunkyBob
        theWhisper_: but department has a relation to employee, right/
      • so you can follow that relation backwards, like in the link I gave you
      • Oli has quit
      • theWhisper_
        FunkyBob: i read it but not following the logic yet
      • FunkyBob: I have a employee table with x number of employees
      • this model has only 2 fields firtname and lastname
      • Dunedan_ joined the channel
      • i have a model called deprtments which is already populated with 10 departments which i will use to populate a select input field in html
      • FunkyBob
        actually, it has 3.. the id, which is implied... but meanwhile...
      • theWhisper_
        the department model has a name and a user field with a manytomany relation to employee
      • FunkyBob
        this doesn't change that there is a _relation_ between Employee and Department...
      • allowing you to filter across that relation
      • theWhisper_
        i see but since i am not creaing any to department
      • pytony has quit
      • the departments already exist
      • FunkyBob
        yes
      • Oli joined the channel
      • theWhisper_
        but there is no field in the database like employee_id
      • FunkyBob
        btw -- since it's a many-to-many, neither model has any fields for that relation... there's an implied "through" table that has the fields
      • theWhisper_
        to set the relation
      • so when a employee choose a department what happens?
      • FunkyBob
        right... there is a through table which has (pk, employee_id, department_id)
      • theWhisper_
        say employee x wants to add his finance department
      • FunkyBob
        to relate an employee to a department, a new entry is put in that through table
      • theWhisper_
        ohh but i dont see it?
      • FunkyBob
        this was, I believe, in the docs that schinckel linked yuo to
      • right... it's hidden away for convenience
      • theWhisper_
        normally the join table has to be created in php
      • Dunedan has quit
      • FunkyBob
        [however, you _can_ explicitly declare a m2m through table, for special cases]
      • yeah, well, that's PHP... this isn't
      • theWhisper_
        i see
      • FunkyBob
        though it's unfair to blame PHP directly... Python doesn't hide the m2m tables either
      • theWhisper_
        and how would i add the employee to the department then ?
      • FunkyBob
        you would read the docs that schinckel linked you to
      • electricark joined the channel
      • theWhisper_
        i did
      • it says
      • .add
      • FunkyBob
        right... department.employees.add(employee)
      • theWhisper_
        damm thats so weird not to see the join table
      • FunkyBob