Victor
unread,Jul 18, 2016, 12:43:09 PM7/18/16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
My app (FreeBSD, Django 1.9.4, totally developped using the Admin Site) uses, among othe things, the model "Order" and "OrderDetail" as its inline (see below a simplified version).
The "OrderDetail" model overrides the default save by means of a somewhat elaborate save function with a long workflow.
Now it happens that if a user working on the inlines of an Order rapidly and *** frantically **** (or I'd better say "Hysterically") clicks many times on the "Save and continue editing" button the related instance is recorded more than once.
Therefore I would like to disable the "Save", "Save and continue editing", and "add another" buttons while saving inlines at the very beginning of the save function and re-enable them at the very end of it.
How can I do this?
=================
models.py
.................................
class Items(models.Model):
code = models.CharField(primary_key=True,max_length=15,db_column='code')
description = models.CharField(max_length=255, db_column='Description', db_index=True)
category = models.IntegerField(choices=categoria, db_column='Category',default=2)
total_quantity_in_store=models.IntegerField(db_column='total_quantity_in_store', default=0)
def __unicode__(self):
return self.description
class Order(models.Model):
id_order = models.IntegerField(primary_key=True,db_column='id_order')
patient = models.ForeignKey(Patients, db_column='patient')
def __unicode__(self):
return u"Ord.%s per %s" % (self.id_order, self.paziente)
class OrderDetail(models.Model):
id_order = models.ForeignKey(Order,db_column='id_order')
item_code = models.ForeignKey(Items,verbose_name='Items')
quantity = models.IntegerField(db_column='quantity',blank=True,default=0)
def save(self):
# HERE I WOULD LIKE TO DISABLE/MAKE DISAPPEAR THE "Save", "Save and continue editing", and "add another" BUTTONS
.......
super(OrderDetail,self).save()
.......
# HERE I WOULD LIKE TO ENABLE/MAKE APPEAR AGAIN THE "Save", "Save and continue editing", and "add another" BUTTONS
return
==================
admin.py
......................
class OrderDetailInline(admin.TabularInline):
model=OrderDetail
raw_id_fields = ['item_code',]
fields=('item_code', 'quantity',)
class OrderOption(admin.ModelAdmin):
readonly_fields = ['order_id', 'patient']
list_display = ( 'patient','order_id')
fields=( 'order_id', 'patient')
inlines=[OrderDetailInline,]
admin.site.register(Order,OrderOption)
....................
=========================
Ciao
Vittorio