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

  • Home
  • SEARCH
  • 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 673875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:38:38+00:00 2026-05-14T00:38:38+00:00

I have three model classes that look as below: class Model(models.Model): model = models.CharField(max_length=20,

  • 0

I have three model classes that look as below:

class Model(models.Model):
   model = models.CharField(max_length=20, blank=False)
   manufacturer = models.ForeignKey(Manufacturer)
   date_added = models.DateField(default=datetime.today)
   def __unicode__(self):
      name = ''+str(self.manufacturer)+" "+str(self.model)
      return name 

class Series(models.Model):
   series = models.CharField(max_length=20, blank=True, null=True)
   model = models.ForeignKey(Model)
   date_added = models.DateField(default=datetime.today)
   def __unicode__(self):
      name = str(self.model)+" "+str(self.series)
      return name
class Manufacturer(models.Model):
   MANUFACTURER_POPULARITY_CHOICES = (
      ('1', 'Primary'),
      ('2', 'Secondary'),
      ('3', 'Tertiary'),
   )

   manufacturer = models.CharField(max_length=15, blank=False)
   date_added = models.DateField(default=datetime.today)
   manufacturer_popularity = models.CharField(max_length=1,
      choices=MANUFACTURER_POPULARITY_CHOICES)
   def __unicode__(self):
      return self.manufacturer

I want to have the fields for model series and manufacturer represented as dropdowns instead of text fields. I have customized the model forms as below:

class SeriesForm(ModelForm):
   series = forms.ModelChoiceField(queryset=Series.objects.all())
   class Meta:
      model = Series
      exclude = ('model', 'date_added',)

class ModelForm(ModelForm):
   model = forms.ModelChoiceField(queryset=Model.objects.all())
   class Meta:
      model = Model
      exclude = ('manufacturer', 'date_added',)

class ManufacturerForm(ModelForm):
   manufacturer = forms.ModelChoiceField(queryset=Manufacturer.objects.all())
   class Meta:
      model = Manufacturer
      exclude = ('date_added',)

However, the dropdowns are populated with the unicode in the respective class…how can I further customize this to get the end result I want?

Also, how can I populate the forms with the correct data for editing? Currently only SeriesForm is populated. The starting point of all this is from another class whose declaration is as below:

class CommonVehicle(models.Model):
   year = models.ForeignKey(Year)
   series = models.ForeignKey(Series)
   ....

   def __unicode__(self):
      name = ''+str(self.year)+" "+str(self.series)
      return name 
  • 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-14T00:38:39+00:00Added an answer on May 14, 2026 at 12:38 am

    Check out http://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield and in particular the chunk that starts

    The unicode method of the model will be called to generate string representations of the objects for use in the field’s choices; to provide customized representations, subclass ModelChoiceField and override label_from_instance. This method will receive a model object, and should return a string suitable for representing it.

    [There then follows a good example of how to do that]

    HTH

    Steve

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

Sidebar

Ask A Question

Stats

  • Questions 411k
  • Answers 411k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your query is perfectly fine for the intended use, but… May 15, 2026 at 7:40 am
  • Editorial Team
    Editorial Team added an answer Solved the issue by changing replacing xml: with a namespace… May 15, 2026 at 7:40 am
  • Editorial Team
    Editorial Team added an answer <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <!--… May 15, 2026 at 7:40 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.