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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:27:22+00:00 2026-06-05T02:27:22+00:00

I am building a block system with a base block model with each type

  • 0

I am building a block system with a base block model with each type of block a separate subclass like so:

class BlockType(models.Model):
    ''' Defines properties of a block '''
    title = models.CharField(max_length=50)
    class_name = models.CharField(max_length=50)

class Block(models.Model):  
    ''' Implementation of the block '''
    product = models.ForeignKey('product.Product', related_name='blocks')
    block_type = models.ForeignKey('product.BlockType', related_name='used_blocks')
    order = models.IntegerField(default=0)

class ImageBlock(Block):
    ''' An image block '''
    image = models.CharField(max_length=255)

class TextBlock(Block):
    ''' A text block '''
    text = models.TextField()

What I’d like to be able to do is:

b = product.blocks.all()

And instead of this being a list of Block objects. Being a list of relevant subclasses.

So if a product had a TextBlock and 2 ImageBlocks. The above would have returned a TextBlock object and 2 ImageBlocks rather than 3 Block objects.

  • 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-05T02:27:23+00:00Added an answer on June 5, 2026 at 2:27 am

    I’m affraid you can’t do that. But the question is: why you want to do that?

    Before continuing, i have another question: Did you know that modeling these “blocks” the way you did you will get 3 different tables (4 with the “BlockType” table) in your database? Is that what you want?

    I don’t know what you are going to do with these models and how you want to use them, so i will give you some links i think can help you a lot. If you want, you could give us more information about what you are going to do with these models and why you want to have a single queryset with two different models so we can really help you.

    This could help you: https://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models

    or this: https://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-classes

    Hope it helps! If no, please add more info in order to help us understand your problem and try to give you an answer

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

Sidebar

Related Questions

I'm building a Windows Service base class to manages the polling off a schedule's
Building a new ASP.net application, and planning to separate DB, 'service' tier and Web/UI
Does anyone tell me how to block some specific system calls within a program,
i'm building a message system for a virtual community, but i can't take the
I am reading The thread building block book. I do not understand this piece
I'm building a toy VM that requires a block of memory for storing and
I'm building a system health screen in a web UI for an appliance. Part
I am building a batch processing system. Batches of Units come in quantities from
Im building a wpf app with the composite application block (prism) V2, and Im
I'm building an extension to add a specific block right before the 'Place Order'

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.