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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:22:30+00:00 2026-06-09T14:22:30+00:00

In Django, I have the following models.py class Product(RandomPrimaryIdModel): title = models.CharField(max_length=20, blank=True, null=True)

  • 0

In Django, I have the following models.py

class Product(RandomPrimaryIdModel):
  title = models.CharField(max_length=20, blank=True, null=True)
  price = models.CharField(max_length=20, blank=True, null=True)
  condition = models.CharField(max_length=20, blank=True, null=True)

class Mattress(Product):
  length = models.CharField(max_length=50)
  size = models.CharField(max_length=5)

class Pillow(Product):
  shape= models.CharField(max_length=50)
  comfort= models.CharField(max_length=5)     

The idea is that there’s a “product” model and several “product_type” models. I’m trying to create a database scheme that relates the two. The end goal is so that when I given access to a primary id for an object whose product_type is unknown, I can simply query/filter that object to find out what the product_type is of the object.

I know that sounds a bit confusing, but how would I go about implementing the correct way? The current scheme (the one above) is not the correct solution I believe.

  • 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-09T14:22:31+00:00Added an answer on June 9, 2026 at 2:22 pm

    According to the docs on multi-table inheritance you can reference the lowercase name of the model. In your case to find out the “product type” you’d do something like:

    product = Product.objects.get(id=12)
    try:
        mattress = product.mattress
        is_mattress = True
    except Mattress.DoesNotExist:
        is_mattress = False
    

    You could abstract this out to a helper method that would do the tests for you and return the type as a string or enum of some sort.

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

Sidebar

Related Questions

In Django, I have the following models.py class Product(RandomPrimaryIdModel): feature1 = models.CharField(max_length=20, blank=True, null=True)
I have the following abstract Django models: class Food(models.Model): name = models.CharField(max_length=100) class Meta:
I have the following Django models: - class Company(models.Model): name = models.CharField(max_length=50) is_active =
I have following models class Artist(models.Model): name = models.CharField(max_length=200, unique=True) photo = models.CharField(max_length=250) views
I have the following model: from django.db import models class State(models.Model): name = models.CharField(max_length=30)
I have the following models: class Bill(models.Model): date = models.DateTimeField(_(Date of bill),null=True,blank=True) class Item(models.Model):
In my Django App I have the following model: class SuperCategory(models.Model): name = models.CharField(max_length=100,)
I have following models relation: class Section(models.Model): section = models.CharField(max_length=200, unique=True) name = models.CharField(max_length=200,
in a django-tastypie app I have the following Django-models: class Car(models.Model): name=models.CharField('name',max_length=64) class CarTrack(models.Model):
I have the following model. from django.db import models class Client(models.Model): postcode = models.CharField(max_length=10)

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.