django+modelform+Foreignkey

154 views
Skip to first unread message

H.İbrahim Yılmaz

unread,
Mar 6, 2010, 4:36:14 PM3/6/10
to django...@googlegroups.com
Hi all,
I have some ModelForms.. This ModelForms based some ForeignKey
included models. When i want to create a ModelForm I got these
ForeignKey fields something like (in a dropdown menu) "BlaBla object".
But i want to get in that dropdown menus something like "Linus
Torvalds". I mean how can I show in that fields that Models name area
or adress area?
I made my ModelForm like that :

class Author

class AuthorForm(ModelForm):
      class Meta:
      model = Author
      exclude = ("status",)

--
http://www.arkeoloji.web.tr

Arkeoloji.web.tr

unread,
Mar 6, 2010, 4:39:59 PM3/6/10
to django...@googlegroups.com
Hi all,
I have some ModelForms.. This ModelForms based some ForeignKey
included models. When i want to create a ModelForm I got these
ForeignKey fields something like (in a dropdown menu) "BlaBla object".
But i want to get in that dropdown menus something like "Linus
Torvalds". I mean how can I show in that fields that Models name area
or adress area?
I made my ModelForm like that :

class Author(models.Model):
name = models.ForeignKey(User)
status = models.CharField(max_length=30)

Kev Dwyer

unread,
Mar 7, 2010, 8:14:45 AM3/7/10
to django...@googlegroups.com

Hello,

Try giving your models a __unicode__ method, so that you can
manage how they are displayed.

For example:

class Author(models.Model):
name = models.ForeignKey(User)
status = models.CharField(max_length=30)

def __unicode__(self):
return self.name

Cheers,

Kev

Dennis Kaarsemaker

unread,
Mar 7, 2010, 8:20:36 PM3/7/10
to django...@googlegroups.com
On za, 2010-03-06 at 23:36 +0200, H.İbrahim Yılmaz wrote:
> Hi all,
> I have some ModelForms.. This ModelForms based some ForeignKey
> included models. When i want to create a ModelForm I got these
> ForeignKey fields something like (in a dropdown menu) "BlaBla object".
> But i want to get in that dropdown menus something like "Linus
> Torvalds". I mean how can I show in that fields that Models name area
> or adress area?

This is something you need to fix in your Model, not your ModelForm.
Give the Model a __unicode__ method.

--
Dennis K.

The universe tends towards maximum irony. Don't push it.

H.İbrahim Yılmaz

unread,
Mar 10, 2010, 12:33:58 PM3/10/10
to django...@googlegroups.com
Thanks! "It Works!" ;)
2010/3/7 Kev Dwyer <kevin....@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>

--
http://www.arkeoloji.web.tr

Reply all
Reply to author
Forward
0 new messages