Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3595560
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:52:06+00:00 2026-05-18T19:52:06+00:00

I have a ForeignKey field in a model of mine, and I’m using ModelForm

  • 0

I have a ForeignKey field in a model of mine, and I’m using ModelForm with it to generate the HTML. The thing is, I want to add an Other option as well – I plan to add JavaScript with it so that a textbook appears when that’s selected.

I’m looking at http://docs.djangoproject.com/en/1.2/topics/forms/modelforms/#overriding-the-default-field-types-or-widgets, and started off with trying something like

class Event(models.Model):
    name = models.CharField(max_length=200)
    time = models.DateField()
    .
    .
    .
    cost = models.CharField(max_length=200)
    affiliation = models.ForeignKey('Affiliation')
    def __unicode__(self):
        return self.name

class EventForm(ModelForm):
    cost = models.TextField()
    class Meta:
        model = Event

cost should become a text field instead of char field, so the output should be textarea instead of input[type=text]. This doesn’t change, however, no errors are printed, and nothing really happens. I was hoping to proceed by doing

class EventForm(ModelForm):
    affiliations = list(Affiliation.objects.all()).append('Other')
    affiliation = forms.CharField(choices=affiliations)
    class Meta:
        model = Event

I’m using django-nonrel on GAE if it helps, but this isn’t really an issue with the Model (or so I think…) so I don’t think it should change anything. Any help would be much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T19:52:06+00:00Added an answer on May 18, 2026 at 7:52 pm

    I haven’t used django-nonrel, so take this tip with a grain of salt (YMMV).

    In your EventForm definition, you’re setting cost to be a model.TextField – but you actually want it to be a forms.CharField, with a textarea widget.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
I have the following model field: name = models.ForeignKey(User, unique=False, editable=False, limit_choices_to= {'is_staff': False})
I have a model which has a ForeignKey field, and I wish to change
I have two models: A(models.Model): field = models.IntegerField() B(models.Model): f = models.ForeignKey(A) And in
I have a model with a foreign key field user = models.ForeignKey(User) which links
I have model with an optional ForeignKey field. I need filter all records with
I have a model, one field of it is a ForeignKey, so i see
In my Django project I want to change a model field from ForeignKey to
I have two Model's which are related with a ForeignKey field. Let's call these
I have a model that references a ForeignKey(User) field. When a user selects an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.