Monday, July 23, 2018

Django admin panel records disappearing

Hello,

I am using the Django admin tool as an internal tool to reach into a remote database.

Most of my models work perfectly with the save. method additions I have added, but there are 2 that are not working.

What happens is that the admin screen gives a successful "save" message, but the grid view doesn't show any records.

When I click on the entry in the right hand "Recent changes" list, it says:

Change learner batch back to draft with ID "None" doesn't exist. Perhaps it was deleted?

Any advice on why this is happening would be welcome :)

Here is the model in question:

class ChangeLearnerBatchBackToDraft(models.Model):
ticket_number = models.CharField(max_length=10, default='')
provider_accreditation_num = models.CharField(max_length=30)
batch_id = models.CharField(max_length=30)
notes_log = models.TextField(default="No notes added", editable=False)

def save(self, *args, **kwargs):
try:
commando_conn = psycopg2.connect(f"dbname='{DB}' user='{USER}' host='{HOST}' password='{PASS}'")
commando_cur = commando_conn.cursor()
commando_cur.execute(f"select * from res_partner where provider_accreditation_num='{self.provider_accreditation_num}';")
res = commando_cur.fetchone()
real_provider_id = res[0]
self.notes_log = self.notes_log+f"\n{real_provider_id}\n"
except Exception as e:
raise AssertionError(e)

def __str__(self):
return str(self.provider_accreditation_num)+" - "+str(self.batch_id)

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/29e2a257-2631-4075-9453-8ce95b068f8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment