How do I handle multiple user selected actions when updating my database via CSV?

I'm working on a database of shows which has models for Actors, Characters, and Shows.

I'm trying to implement a Bulk Upload feature that accepts a CSV file. I'm starting with bulk uploading shows, here's the relevant model:

class Show(models.Model:
    title = models.CharField(max_length=2083, blank=True, null=True)
    blurb = RichTextField(blank=True)
    website = models.CharField(max_length=2083, blank=True, null=True)
    host = models.ManyToManyField('Host', through='ShowHosts', blank=True)

Currently, when the file is submitted, the site checks the 'Title' and 'Host' fields against existing records in the database and, if there are no duplicates, it creates a new instance of the 'Show' and 'Host' and assigns the new 'Host' to the new 'Show'.

Where I need assistance is what happens when a duplicate is found. This is how I'd like to handle it:

The user is redirected to a new page containing a table. Each row has three columns; the first contains a dict consisting of the uploaded info for the new show, the second contains the Model Object of the duplicate Show/Host that was found in the database already, the third is a element prompting the user to choose how they'd like to handle the duplicate. Here's an example of the results when one of the rows of the file returns a duplicate Title and a different row returns a duplicate Host

Uploaded Show Existing Record Action
{upload_row: '1', title: 'A Show Called Something', host: 'Mr. Person'} Show: "A Show Called Something" [Select Action]
{upload_row: '4', title: 'A New Show', host: 'Some Guy'} Host: "Some Guy" [Select Action]

I've been able to generate this table just fine, but I can't figure out how to handle the Action Selection process. Let's assume that user would like to confirm that 'A Show Called Something' is a new show with the same name as the Existing Record but that 'Some Guy' is the same person that was found in the database.

In the Action column, I'd like my user to be able to select "Create New Record" for the first row and "Use Existing Record" for the second row. I already have working functions for each of these choices, I just don't know how to allow for the user to make their selection and then pass the corresponding dictionaries to the appropriate functions.

I have a feeling that my solution is going to have something to do with utilizing jquery but I only just started looking into that for this project so I'm unsure how

Many thanks in advance for any insight you can offer!

Back to Top