I have the following models and admin files and I would like to be able to 
show the text representation of the ExpenseCategory category field in the 
dropdown list on the Admin page. However, the dropdown list is displaying 
"ExpenseCategory Object(n)" instead of the actual text category such as 
"Utilities", "Office Supplies" etc. 

I need to insert the ExpenseCategory pk in the Expenses table but want a 
human readable drop down list to show the category text instead. 

Any guidance would be appreciated. Thanks in advance......
  

MAIN/MODELS>PY

class ExpenseCategory(models.Model):
    category = models.CharField(max_length=200)
    deductible = models.TextField(choices=BOOLEAN_CHOICE)

    def __int__(self):
       return self.category

class Expenses(models.Model):
    expense = models.CharField(max_length=200)
    category = models.ForeignKey(ExpenseCategory, on_delete=models.PROTECT)
    expense_amount = models.DecimalField(max_digits=8, decimal_places=2)
    expense_date = models.DateField(auto_now_add=False)
    expense_type = models.TextField(choices=SOURCE)
    description = models.CharField(max_length=200)
    source = models.CharField(max_length=200)

    def __int__(self):
       return self.expense
------------------------------------
MAIN/ADMIN.PY

class ExpenseCategoryAdmin(admin.ModelAdmin):
   list_display = ['category','deductible']
   list_filter = ['deductible']

admin.site.register(models.ExpenseCategory, ExpenseCategoryAdmin)

class ExpensesAdmin(admin.ModelAdmin):
   list_display = 
['expense','expense_amount','expense_date','category','expense_type']
   list_filter = ['expense_date','category','expense_type']

admin.site.register(models.Expenses, ExpensesAdmin)



-- 
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/b0d5e22e-2d20-4e11-ac22-00fb1eb9794f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to