earlier this week, I asked this question about having foreign keys in your main model from your subclasses: Django Form With Foreign Key
I used the answer given to make a model and sub-models (code at the end). My question is, I know about admin inlines for foreign keys, but I can't use that since the main model has the foreign key to the subclasses, not the other way around. I want the foreign keys in my main class to be displayed in the admin.
Sorry it that sounds confusing, here's my model:
Subclass 1 PreObservation
class PreObservation( models.Model ):
pre_observation = models.CharField(
max_length=255,
choices=OBS_STANDARD_TYPES,
verbose_name="Pre-Observation Standard"
)
obs__meter_reading = models.FloatField( blank=True, null=True )
obs_if_other = models.FloatField( blank=True, null=True )
Subclass 2 FieldObservation
class FieldObservation( models.Model ):
site_id = models.CharField( max_length=255, choices=STATION_CHOICES )
site_name = models.CharField( max_length=255 )
stage_reading = models.FloatField( )
specific_conductance = models.FloatField( )
water_temp = models.FloatField( )
Main class Record
class Record( models.Model ):
observers = models.CharField( max_length=255, verbose_name="Name of Observer(s)")
pre_observation_standard_1 = models.ForeignKey(
PreObservation,
related_name="pre_observation_1"
)
pre_observation_standard_2 = models.ForeignKey(
PreObservation,
related_name="pre_observation_2",
blank=True, null=True
)
field_observation_1 = models.ForeignKey(
FieldObservation,
related_name="field_observation_1"
)
field_observation_2 = models.ForeignKey(
FieldObservation,
related_name="field_observation_2",
blank=True, null=True
)
cloud_coverage = models.CharField( max_length=255, choices=CLOUD_COVERAGE )
rain_past_three_days = models.BooleanField( verbose_name="Rain in Past 3 Days" )
snow = models.BooleanField( )
snow_melt = models.FloatField( )
temperature = models.CharField( max_length=255, choices=TEMPERATURE )
wind = models.CharField( max_length=255, choices=WIND )
field_notes = models.TextField( )
teachers_comments = models.TextField( )
user = models.ForeignKey( User )
group_name = models.CharField( max_length=255, blank=True )