--(Unsigned mail from my phone)
-------- Original message --------From: Ryan Nowakowski <[email protected]> 
Date: 13/6/22  07:09  (GMT+10:00) To: [email protected] Subject: 
Re: How to hash fields and detect changes in a record On Sat, Jun 11, 2022 at 
12:13:16AM +1000, Mike Dewhirst wrote:> On 10/06/2022 11:24 pm, Ryan Nowakowski 
wrote:> > On Fri, Jun 10, 2022 at 05:52:48PM +1000, Mike Dewhirst wrote:> > > I 
think the solution might be to hash note.title and note.note into a new> > > 
field note.hash on being auto-created. On subsequent saves, compare the> > > 
latest hash with note.hash to decide whether to delete auto-inserted notes> > > 
prior to generating the next set. Those subsequent saves could be months or> > 
> years later.> > Hashing is useful if you want to check that something has 
been> > unexpectedly changed.  I assume the note can only be changed through> > 
your web app so you know when a user is changing a note.> > These are 
automatically generated notes which taken together constitute> advice on how to 
deal with the analysis. Users can edit them. For example,> someone might record 
some action taken regarding the advice. I don't want to> delete that. If 
nothing has been edited, it is safe to delete.> > So how do I know it is the 
same as when originally generated - and safe to> delete - except by storing a 
hash of the interesting fields.Because when the user edits a note, during the 
form.save()(assumingyou're using Django forms), you'll set `altered_by_user` to 
True.Notes can also be altered in the Admin> And if that is the best approach, 
what sort of hashing will survive Python> upgrades etc?Pick a hash 
algorithm[1](ex: sha256).  The output will remain the sameeven with Python 
upgrades.So the mechanism doesn't need to be a hash - as you said. I now just 
sum ord(char) for the title and the note and keep that in a flag field.Only the 
auto-notes get a flag because they are the only ones I would consider deleting. 
[1] https://docs.python.org/3/library/hashlib.html> > Since you're> > expecting 
users to change some of the notes and you know when they do,> > hashing might 
be overkill.  Instead, add a boolean `altered_by_user`> > field to the note 
model.  Initially when you automatically create the> > note altered_by_user 
would be set to False.  If a user changes the note,> > set altered_by_user to 
True.>> Not sure this would work. Note creation and eventually automatic 
deletion is> all driven from model methods executed on saving.Why wouldn't this 
work? During note creation, altered_by_user would beset to False automatically 
because that's the default.  Whenautomatically deleting, do:    
Note.objects.filter(altered_by_user=False).delete()-- You received this message 
because you are subscribed to the Google Groups "Django users" group.To 
unsubscribe from this group and stop receiving emails from it, send an email to 
[email protected] view this discussion on the web 
visit 
https://groups.google.com/d/msgid/django-users/20220612210931.GA32625%40fattuba.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/62a6c0f0.1c69fb81.c1d5.c26fSMTPIN_ADDED_MISSING%40gmr-mx.google.com.

Reply via email to