On 3 February 2011 16:14, Bobby Roberts <tchend...@gmail.com> wrote: > considering this model: > > class Inventory (models.Model): > id = models.AutoField (primary_key=True) > Barcode = models.BigIntegerField(blank=False) > Location = models.CharField (max_length=25,blank=False, > db_index=True) > Sku = models.CharField (max_length=25,blank=False, > db_index=True) > Quantity = models.DecimalField (blank=False, max_digits=7, > default=0,decimal_places=2,help_text='Quanity on barcode') > LastAction = models.ForeignKey('AppSettings.InventoryOption', > verbose_name=_('Last Action'), related_name='LastAction',blank=False, > null=False) > LastTouchedBy = models.ForeignKey(User, unique=False, > db_index=True, blank=False) > LastUpdated = models.DateTimeField > (auto_now_add=True,blank=False, db_index=True,help_text='Auto Filled') > > class InventoryAdmin(admin.ModelAdmin): > list_display = > ('Barcode','Sku','Location','LastAction','LastUpdated','User.first_name',) > search_fields = ['Barcode','Location','Sku','LastTouchedBy'] > readonly_fields = > > ['BarCode','Location','Sku','Quantity','LastAction','LastTouchedBy','LastUpdated'] > admin.site.register(Inventory,InventoryAdmin) > > > > two questions. > > 1) LastTouchedBy is the userid - what do i need to do to print out the > firstname+lastname of the user in the list_display. (ie instead of > printing out userid 123, I want to print out the user's full name, > "john doe" >
2) LastAction - I'm importing AppSettings model further up the page, > how can I print out the text value of > (AppSettings.InventoryOption.name) in place of the numerical value > stored in LastAction > > Hi Bobby, You might be able to do this with python property decorators for both these questions. Ie: class Inventory(models.Model): @property def touched_by_name(self): return self.LastTouchedBy.get_full_name() @property def inventory_option_name(self): return self.AppSettings.InventoryOption.name class InventoryAdmin(admin.ModelAdmin): list_display = ('Barcode','Sku','Location','LastAction','inventory_option_name','LastUpdated','touched_by_name',) - Karl > > rapid help greatly appreciated. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.