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 7648035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:36:38+00:00 2026-05-31T10:36:38+00:00

I have a WorderOrder class that has predefined work order types: class WorkOrder( models.Model

  • 0

I have a WorderOrder class that has predefined work order types:

class WorkOrder( models.Model ) :
    WORK_TYPE_CHOICES = (
        ( 'hc', 'Heating and cooling' ),
        ( 'el', 'Electrical'          ),
        ( 'pl', 'Plumbing'            ),
        ( 'ap', 'Appliances'          ),
        ( 'pe', 'Pests'               ),
        ( 'ex', 'Exterior'            ),
        ( 'in', 'Interior'            ),
        ( 'ot', 'Others'              ),
    )

    work_type = models.CharField( max_length = 2, choices = WORK_TYPE_CHOICES )
    vendor    = models.ForeignKey( Vendor, null = True, blank = True )

Therefore each order must have one work order type. Later down the road, a vendor can also be assigned to a work order.

I want the Vendor class to have a M2M relationship to the same work order choices in the WorkOrder class. In other words, each vendor are able to do one or many work types. For example, Bob’s Plumbing can only do “Plumbing”, whereas Solid Home Repair can do “Electrical”, “Plumbing”, “Exterior”, and “Interior”.

I understand I can create another table called WorkType and use foreign keys from WorkOrder and a M2M from Vendor, but since I feel I won’t be changing the work type choices, I would rather have them predefined in models.py.

Also if I can predefine it in models.py, then I don’t have to pre-populate the table WorkType during deployments and upgrades.

  • 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-31T10:36:40+00:00Added an answer on May 31, 2026 at 10:36 am

    Some options for you:

    1. create a model for work_type_choices, instantiate the records (hc, el, etc), then use a manytomany field, or

    2. create a charfield and save CSV values to it (eg: “hc, el”), spliting/joining the value into it’s elements as required, or

    3. encapsule the above charfield and functions into a custom field and use that

    4. leverage someone else’s snippet, eg:
      http://djangosnippets.org/snippets/1200/

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

Sidebar

Related Questions

Have you managed to get Aptana Studio debugging to work? I tried following this,
Have converted devise new session from erb to Haml but doens't work, this is
Have a bunch of WCF REST services hosted on Azure that access a SQL
Have a look at one of my websites: moskah.com The problem is that it
Have a simple contact us XPage created. Have server side validation in place that
Have a really weird one here. The app has two targets, just to be
Have some dates in my local Oracle 11g database that are in this format:
Have an app that can use tts to read text messages. It can also
Have a fun issue with sharepoint calendar view filtering. That code works fine: SPSecurity.RunWithElevatedPrivileges(delegate()
Have a rails app that is supposed to display a list of products/managers. After

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.