anschelburk / simple_planner

Apache License 2.0
0 stars 0 forks source link

Check-In #3: Multiple Lists (Debugging) #25

Closed anschelburk closed 3 months ago

anschelburk commented 3 months ago

Hi Bob,

I'm a bit stuck at this point refactoring the code using a many-to-one relationship. I'm going to try and describe where I'm getting stuck, and I'm hoping tomorrow that we can check in about:

  1. The answer to my question, and
  2. How you might approach this issue in a software engineering role, if you were in my shoes.

The basic question I'm getting stuck on is this: in Django, when is a primary key created for a given user input?

Here's what I mean. In the previous app I worked on, I essentially had a linear form with a series of inputs, each rendered a single time:

Teacher Name: [input] Student Name: [input] etc.

That all made sense: each one of those things was saved to a database, and each received its own primary key.

But in this app, we're doing something different: we essentially have two fields (a list name and a list item) that are repeated over and over again on the same page:

[Instance 1]

[Instance 2]

etc.

So if the same two model fields are repeated over and over again, how would they have different primary keys? When would those primary keys be assigned? Ultimately, in order to properly code this, I understand that I need to give Django a way to tell these different iterations of the same two model fields apart. Before, it was very easy to see how Django distinguished between the lists: I explicitly defined a for loop that gave each list a unique number as it was rendered. With primary keys, I'm getting stuck on how two model fields that get repeated over and over again (list name and list item) could have different primary keys.

Does that make sense? Would love to talk more about this tomorrow - particularly, to just talk through together how you would approach this if you encountered this in a software development role, and didn't know the answer. I pushed my code, though honestly I spent most of my time trying to think this question thorough.

Looking forward to checking in tomorrow.

Best, Anschel