Monday, May 20, 2013

Inserting a search field into a tabularline inline

As a newby I started an app that works quite fine. Here are the models (Forgive some 'slip of the tongue' but I had to translate my *.py's into English and simplify them):

In models.py
.........................
.........................
class Item(models.Model):
id = models.AutoField(primary_key=True)
barcode = models.CharField(max_length=30, unique=True, db_index=True) # Field name made lowercase.
description = models.CharField(max_length=255, db_column='Descrizione') # Field name made lowercase.
def __unicode__(self):
return self.description
class Meta:
ordering=['description']


class Operation(models.Model):
id = models.AutoField(primary_key=True) # Field name made lowercase.
sign = models.IntegerField(choices=((-1,u'Item in'),(1,u'Item out')),
default=-1,verbose_name=u'OPERATION') # Field name made lowercase.
op_date=models.DateTimeField()
class Meta:
ordering=['-op_date']

class OperationDetail(models.Model):
operation = models.ForeignKey(Operation) # Field name made lowercase.
itemdescription = models.ForeignKey(Item) # Field name made lowercase.
quantity = models.IntegerField(null=True) # Field name made lowercase.
....................

in admin.py
...................
class OperationDetailInline(admin.TabularInline):
model=OperationDetail
extra=1
save_on_top=True

class OperationOption(admin.ModelAdmin):
list_display = ('sign', 'op_date')
fields=('sign', 'op_date')
inlines=[OperationDetailInline,]
save_on_top=True
order_by=['-op_date',]
..................
admin.site.register(Operation,OperationOption)



You see that the field itemdescription (unique=True) of the OperationDetail model is linked to Item by means of a foreignkey.


NOW, because this django procedure is going to be operated by people mainly using barcode readers what I eagerly need is to put a search_field (like the option available in ModelAdmin) in OperationDetailInline so that people can add the inline records by reading the barcode readers the barcode (which is a field of the related Item model) as text, click on "search" and have the field itemdescription filled with the related item description. Then they can fill the remaining fields manually.
Is it possible to reach this result and how?
Ciao from Rome
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate