Django database records not showing in database after saving

Hi Guys,
I am developing a database application using django, initially when i add records it saves successfully and the record could be found in the database. I am almost done with the application, however, I don’t know what happened now when I add new records recently django says it has been saved but I go to the database and can’t find the record. Also if I edit old records and save, the record doesn’t get updated. I have tried this both from the admin and from the user end but same issue. No error shows in the console, everything seems to work fine but record added cannot be found. What could possibly be wrong? Please help, I could share any part of my codes you want me to, this is really delaying my project. This is my model

from django.db import models
from django.urls import reverse
from openbabel import pybel


class Molecule(models.Model):
	YES_OR_NO = (
		('Yes','Yes'),
		('No', 'No'),
		)

	STORAGE_FORMAT = (
		('Ind_vial','Individual vial'),
		('96wp', '96 well plate'),
		('384wp', '384 well plate'),
		)

	STORAGE_TEMPERATURE = (
		('4','4 degrees'),
		('-20', '-20 degrees'),
		('-80', '-80 degrees'),
		)

	DRY_OR_LIQUID = (
		('dry','dry'),
		('liquid', 'liquid'),
		)

	STORAGE_TYPE = (
		('Storage Pod','Storage Pod'),
		('Non Storage Pod', 'Non Storage Pod'),
		)


	date_added = models.DateField(null=True, blank=True) #Fixed
	compound_structure = models.ImageField(null=True, blank=True, upload_to = "compound_images/", help_text='Upload image of the compound structure') #Image of the compound structure

	compound_id = models.CharField(max_length=30,unique=True, help_text= 'Enter compound id') # This is a unique id
	local_name = models.CharField(max_length=100,blank=True, null=True, help_text='Enter local name')
	commercial_name = models.CharField(max_length=100,blank=True, null=True, help_text='Enter compound commercial name')
	cas_number = models.CharField(max_length=100,blank=True, null=True, help_text='Enter CAS number')
	product_code = models.CharField(max_length=100,blank=True, null=True, help_text='For only purchased compounds') #fixed


	compound_library_name = models.CharField(max_length=200,verbose_name='Compound Library Name', help_text='Enter the compound library name')
	compound_origin = models.CharField(max_length=200,help_text='Enter the compound origin name')

	au_contact_person_name = models.CharField(max_length = 250,verbose_name ='AU Contact Name', blank=True, null=True,help_text='Enter full name' )
	au_contact_person_email = models.EmailField(max_length = 250,verbose_name ='AU Contact Email', blank=True, null=True,help_text='Enter email address' ) 


	plate_id = models.CharField(max_length=100,blank=True, null=True, help_text='Enter Plate Id') #New variable because foreign key giving me a lot of issues

	solubility_and_solvent_to_use = models.TextField(max_length=200,null=True, blank=True, help_text='Solvent and solvent to use')



	comments = models.TextField(max_length=1000, null=True, blank=True, help_text='Additional information') # Comments/ additional information
	

	#Make sure you put storage under one session
	quantity_received = models.CharField(max_length =10, choices = DRY_OR_LIQUID, blank = True, help_text = 'Quantity received')
	weight = models.FloatField(null=True, blank=True, help_text= 'Enter weight if dry (in mg)')
	volume = models.FloatField(null=True, blank=True, help_text= 'Enter volume if liquid (in μL)')
	storage_type = models.CharField(max_length =20, choices = STORAGE_TYPE, blank = True, help_text = 'Type of storage used')

	room_temperature = models.FloatField(null=True, blank=True, verbose_name = 'Room Temperature')
	freezer_temperature = models.CharField(max_length =4, choices = STORAGE_TEMPERATURE, blank = True, help_text = 'Freezer Temperature')
	storage_format = models.CharField(max_length =50, choices = STORAGE_FORMAT, blank = True, help_text = 'Storage format')
	freezer_name = models.CharField(max_length=50, blank=True, null=True, help_text='Freezer name')
	shelf_or_drawer_number = models.IntegerField(blank=True, null=True)
	box_number = models.IntegerField(blank=True, null=True)


	compound_type = models.CharField(max_length=200,blank=True, null=True, help_text='Enter compound type (eg. Small molecule) ')

	molecular_formula = models.CharField(max_length=30,null=True, blank=True,help_text= 'Enter compound formula')
	molecular_weight = models.FloatField(null=True, blank=True, verbose_name = 'Compound molecular weight')
	smiles = models.CharField(max_length=500,null=True, blank=True, help_text= 'Enter compound Smiles')
	inchl_key = models.CharField(max_length=200,null=True, blank=True, help_text= 'Enter compound Inchl key')
	logp = models.FloatField(null=True, blank=True, help_text= 'Enter LogP/LogD ')

	#name annotation
	pubchem_cid = models.IntegerField(blank=True, null=True)
	chembl_id = models.CharField(max_length=30,null=True, blank=True,help_text= 'Enter compound id')
	iupac_name = models.CharField(max_length=500,blank=True, null=True, help_text= 'Enter IUPAC name') #Fixed
	commercially_available = models.CharField(max_length =4, choices = YES_OR_NO, blank = True, help_text = 'Commercial Availability')
	compound_salt_version = models.CharField(max_length=500,blank=True, null=True,help_text= 'Enter compound salt version') #Fixed

	#Activity data
	affects_schistosomula = models.CharField(max_length =4, choices = YES_OR_NO, blank = True, help_text = 'Does compound affect Schistosomula')
	schistosomula_activity = models.FloatField(null=True, blank=True, verbose_name = 'Schistosomula Activity(EC50)', help_text='(in μM)')
	affects_juvenile_worms = models.CharField(max_length =4, choices = YES_OR_NO, blank = True, help_text = 'Does compound affect Juvenile worms')
	juvenile_worms_activity = models.FloatField(null=True, blank=True, verbose_name = 'Juvenile worms Activity(EC50)', help_text='(in μM)')
	affects_adult_worms = models.CharField(max_length =4, choices = YES_OR_NO, blank = True, help_text = 'Does compound affect Adultworms')
	adult_worms_activity = models.FloatField(null=True, blank=True, verbose_name = 'Adult worms Activity(EC50)', help_text='(in μM)')
	adultworm_screen_conducted_by= models.CharField(max_length=100,blank=True, null=True, help_text='Enter name of person who conducted the adultworm screening')
	assay_date = models.DateField(null=True, blank=True)
	previous_assay_date = models.DateField(null=True, blank=True)

	#Biological targets
	putative_human_target = models.CharField(max_length=100,blank=True, null=True, help_text='Enter its putative human target')
	mechanism_of_action = models.TextField(max_length=1000,blank=True, null=True, help_text='Compound mechanism of action')
	invivo_data_available = models.CharField(max_length =4, choices = YES_OR_NO, blank = True, help_text = 'Is there any invivo data on the compound')
	fingerprint = models.TextField(blank=True, verbose_name='Fingerprint')



	def save(self, *args, **kwargs):
		if not self.smiles: # Check if the 'smiles' field is empty
			return
		mol = pybel.readstring("smi",self.smiles)
		fprint = mol.calcfp()
		bitson = fprint.bits
		self.fingerprint = bitson
		super().save(*args, **kwargs)

		

	def __str__(self):

		return self.compound_id 


	class Meta:
		ordering = ['-date_added','compound_id','local_name','compound_library_name','compound_origin']


	def get_absolute_url(self):
		return reverse('compound-detail', args=[str(self.id)])

Side note: When posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted. (I took the liberty of updating your post here - please remember in the future that multi-line code requires separate lines of ``` - the single backtick doesn’t work across multiple lines.)

You’ve got that if statement in your save method. The first thing I’d do is add a print statement in that save method to print self.smiles before the if to verify that it is not blank. If that field is blank or null, no data would be saved.

Beyond that, we may need to see the view that is supposed to update this model and/or the ModelAdmin class for it to try and determine what might be wrong.

You might also want to examine the database directly to verify that you don’t have an empty smiles field for the row you’re trying to update.

Thanks very much for the correction. Its my first time posting here and I thought it was one back tick. I have actually figured out the solution to the problem after posting it here. I rewrote the save function by moving the logic into a different function and calling the function in the save method and this worked for me. This may help somebody because it took me several days to figure this out. I started using django few months ago but from my experience several components need to be made clear or need fixing, i guess its high time we all contribute to make django far better

def generate_fingerprint(self): 
		if not self.smiles:
			return
		mol = pybel.readstring("smi", self.smiles)
		fprint = mol.calcfp()
		bitson = fprint.bits
		self.fingerprint = bitson


def save(self, *args, **kwargs):
	if not self.pk:  # Check if the instance is being saved for the first time
		self.generate_fingerprint()
	super().save(*args, **kwargs)