Hey Mab,

You probably need to replace you `__init__` to `__str__`. They are two
different things.

On Tue, Sep 18, 2018 at 12:18 PM, <mab.mobile...@gmail.com> wrote:

> 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
> <https://groups.google.com/d/msgid/django-users/b0d5e22e-2d20-4e11-ac22-00fb1eb9794f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101 <callto:+555130838101>  |  Mobile: +55 51
<callto:+5551996209291>*99907 0554*

-- 
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/CAEM7gE1GK73r92OPCU0TH02j8Q3M1xSNb3fs9OW5hAkPX-%3DAcg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to