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

-- 
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+unsubscr...@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/E1F69844-31C3-4E92-AC46-ED5F453F776F%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to