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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:47:35+00:00 2026-06-15T22:47:35+00:00

Ok, so I wan’t to create a forum app like this: class Section(models.Model): section_name

  • 0

Ok, so I wan’t to create a forum app like this:

class Section(models.Model):
    section_name = models.CharField(max_length = 200)

class Thread(models.Model):
    title = models.CharField(max_length = 200) 
    content = models.TextArea()

But, I want 4 types of Thread where user can submit text or link or image or link that only contains image. content field will change depending on the types. What is the best approach to do this? Do i need to define SubThread for each type? or can i define like this:

class Thread(models.Model):
THREAD_TYPE = (
    ('text', 'Text'),
    ('link', 'Link'),
        ('imge', 'Image'),
    ('limg', 'Link Image'), 
)

type = models.CharField(max_length = 4, choices = THREAD_TYPE)
    title = models.CharField(max_length = 200) 
if self.type == 'text':
    content = models.CharField(max_length = 200)
# and so on...

Thank you.

  • 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-06-15T22:47:37+00:00Added an answer on June 15, 2026 at 10:47 pm

    You definitely cannot make fields conditional; think about how that would (or wouldn’t) work in the database.

    Creating a sub-class of Thread for each type is an option, but you would have to use GenericForeignKeys to create a relationship between a Thread sub-class and another model. GenericForeignKeys don’t perform as well, if extremely high performance is a major consideration.

    Another option would be to define Thread to support all your types (eg has FileField, URLField) and include a field with choices for the different types. Using the type field, you could specify a template to render the item and/or you could filter by type.

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

Sidebar

Related Questions

I wan't to use this controll in my app but cant find which it
I wan't to search a filename for example like this string: $filetype = file.php.jpg;
I wan to create a pipe between 3 commands: cat = subprocess.Popen(cat /etc/passwd, stdout=subprocess.PIPE)
I wan to monitor changes in android system file /sys/class/net/eth0/operstate for monitoring ethernet state.
Lets say I wan't to add 1 to an integer. This will only be
I wan a regex to alidate all types of possible DN's I create one
i wan to create a program that can get the application name i can
i wan't to know how to generate thumbnails with phpThumb Class, with an array
I wan't to login to a website through Java and perform operations, like click,
I wan't to do some calculated pixelart with OpenCL and display this directly on

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.