I want to generate several related Model objects at once that are linked in the model view via stacked.Inline. I can create the objects in the admin view. However, when I go to the list view of the pipeline model I get:
'Pipeline' object has no attribute 'args'
I have pretty much the same setup working with other models, so I am not sure why it is not working in this case. It complains that 'Pipeline' has no args
model.py:
class Pipeline(models.Model):
config= models.OneToOneField('Config', on_delete=models.SET_NULL, null=True, parent_link=True)
class Config(models.Model):
args = models.CharField(max_length=256, null=True, default='-p -q -x -u -l -m -r')
pipeline = models.OneToOneField('Pipeline', on_delete=models.CASCADE, null=True, parent_link=False)
admin.py:
class ConfigInline(admin.StackedInline):
model = Config
class PipelineAdmin(admin.ModelAdmin):
inlines = [ConfigInline]
I did the database migrations.
You set
parent_link=Truein your one to one field. According to the documentation for it:You obviously don't use this while subclassing another model (This is called multi-table inheritance) hence that doesn't make sense. Change your implementation to:
Furthermore it still doesn't make sense as this way you basically have a foreign in both the tables which I believe is not what you want, keep the relation in only one model (whichever table the foreign key would be better suited to be in according to you):