Starting a procedure when opening a model in the admin interface

9 views
Skip to first unread message

Victor

unread,
Oct 23, 2014, 7:15:51 AM10/23/14
to django...@googlegroups.com
I use Django 1.7, admin interface, and PostgreSQL.
I have, among other things, the following model:

### models.py
class Patients(models.Model):
surname = models.CharField(max_length=60, db_index=True)
name = models.CharField(max_length=60, db_index=True)
address = models.CharField(max_length=150)
city = models.CharField(max_length=120)
zipcode = models.CharField(max_length=15)
def __unicode__(self):
return u"%s %s" % (self.surname, self.name)
class Meta:
db_table = u'patients'
ordering=['surname', 'name']

In this phase of test this model is fed by a python procedure which reads the fields in a a query from an Oracle DB. This procedure for the time being is run manually from time to time when I need to refresh the content of the model.

In production context I would like to start this same python procedure automatically each time a user clicks on the model Patients in the list of models proposed by the admin interface (I mean the one that appears when you call http://localhost:8000/admin) before opening the model itself in order to have its content refreshed to the very last item.

How can I do it?
What kind of signal, if any, should I use?

Ciao
Vittorio

Collin Anderson

unread,
Oct 23, 2014, 8:56:13 AM10/23/14
to django...@googlegroups.com
Hi Vittorio,

I've done something like this before in the get_queryset() method of ModelAdmin.

Thanks,
Collin

Reply all
Reply to author
Forward
0 new messages