Ok so Im saving a CSV document to a Machine object. I want to notifiy the user that the Machine does not exist if it does not exist and exit the save. I first read the CSV file to see what machine the document is for by reading a serial number row.
In my signals:
@receiver(post_save, sender=CSVDocument)
def read_file(sender,instance, signal, created, **kwargs):
...
machine = Machine.objects.get(serial_number=sn)
if not machine:
customNotificationMessage in admin tempalte
I do not want to raise an exception at this stage, rather tell the user there is no such machine, so first create the machine.
Currently if I take out the try block to lookupt the machine it raises the exception:
Machine matching query does not exist. Lookup parameters were {'serial_number': 'NEC03610154'}
I would actually just want this execption as part of the messages after the file is saved.