#14135 closed (invalid)
Admin ignores to_field on ForeignKey
Reported by: | vbs | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.2 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
i am using django 1.2.1. when i use Foreignkey.to_field , the field in the add step of admin still shows "course object", not the char string i specify to. thus i don't know which course i am adding.
it seems like this ticket: http://code.djangoproject.com/ticket/8648, but i am using django 1.2.1
code:
# models.py class course(models.Model): """ course model """ num_of_course = models.CharField(max_length = 32, unique = True) num_of_student = models.IntegerField() send_email_flag = models.IntegerField() timestamp = models.DateTimeField(auto_now_add=True) class ticket(models.Model): """ model for student who asks for the notifier """ user = models.ForeignKey(User) email = models.CharField(max_length = 75) course = models.ForeignKey(course, to_field='num_of_course') email_num = models.IntegerField() stop_email_flag = models.IntegerField() timestamp = models.DateTimeField(auto_now_add=True) #admin.py class TicketModel(admin.ModelAdmin): list_display = ('user', 'email_num', 'course', 'email_num', 'stop_email_flag', 'timestamp') admin.site.register(models.ticket,TicketModel)
Change History (4)
follow-up: 3 comment:1 by , 14 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 14 years ago
but if i just want a specified field rather than an object, how can i do?
Thank you.
comment:3 by , 14 years ago
Replying to mk:
You must define a unicode method on course if you do not want the admin to show "<course object>". This has nothing to do with to_field on a ForeignKey.
but if i just want a specified field rather than an object, how can i do?
Thank you.
comment:4 by , 14 years ago
This is an usage question -- please submit it to the django-users mailing list instead.
You must define a unicode method on course if you do not want the admin to show "<course object>". This has nothing to do with to_field on a ForeignKey.