Django: User Experience for checking if a person already exists in the database (first and last name, and birthday)
[I'm sure my use case has been addressed somewhere, but I'm not finding it.]
In this use case, the user is registering a new person with the following fields: first name, last name, and birthday. If these are the same as an existing entry, the flow is to ask the user if any of the existing entries are the same. If yes, reject the entry. If no, add the entry.
I'm looking for suggestions how to implement this. I know how to check for similar entries. What I'm not sure of is how to ask the "is this a duplicate of any of these other people" question to the user and then process the answer.
Here's what I expect the flow is, and I wonder if there's a better way to do this.
During clean()
on the person entry form, we can query for similar entries (e.g. Jon Smith born 1/1/2000 and John Smith born 1/1/2000) and note there are some (or not). In is_valid()
, if there is possible duplication, the system this would redirect to a view to list the possible duplicates and ask the question in a second form. And then if the user says it's a duplicate then we drop the new entry else we save the new entry.
But this seems like I would have to save the new entry at the end of the first view and then pass it to the second view. And then if the item is a duplicate, I would then have to delete it.
Is there a better way to do this?
Maybe you could save the original entry in request.session
(maybe as JSON data) at the end of the first view, and then only create a real model instance from it if the user rejects the duplicates.
In either case, at the end of the second view you would delete the data from the session.