0

Let say that the model name is BHA, and I populate this field. In Django-Admin homepage, I will have a tab looks like this:

MY_APP_NAME

BHA List
Other Model 1
Other Model 2

Upon clicking BHA List, I will be navigate to a page that has a list of populated BHA:

BHA List

BHA_1
BHA_2
BHA_3
BHA_4

And each BHA needs a separate table that has their own information. So all BHA's (BHA_1, BHA_2, BHA_3, BHA_4) will have exact same child field Bit data, Sensor Data, Component Data. And Each of these sub-fields will have its own subfields too. How should I design my models.py to make this work? Can anyone provide any example code set that enables this feature?

So far I know only a really basic models.py structure that looks like this:

class SomeModel(models.Model):
    field_1 = models.CharField(max_length=100, primary_key=True)
    field_2 = models.CharField(max_length=100)
    field_3 = models.CharField(max_length=100)
Eric Kim
  • 1,977
  • 2
  • 21
  • 49

1 Answers1

1

Technically, these are not child classes. They have no inheritance. If I understand you correctly, you will have to use ForeignKey.

BHA(models.Model):
   bha_name = models.CharField(params)

BitData(models.Model):
    bha = models.ForeignKey(params with reference to BHA)
    model_field = models.CharField(params)

SensorData(models.Model):
    bha = models.ForeignKey(params with reference to BHA)
    model_field = models.CharField(params)

To see them on your page the way you want to will probably involve changing the widget that is used.

You will also have to reference all of your models on the page. Multiple Models Form

Carl Brubaker
  • 1,216
  • 7
  • 18