Referencing a model from another app in admin.py

12 views
Skip to first unread message

dimkouv

unread,
May 10, 2019, 7:58:19 AM5/10/19
to Django users
I'm facing a problem while trying to reference a model from a different app inside admin.py


Let's say for example that inside App1 we have a model called Sensor

#app1 > models.py

class Sensor(models.Model):
   ...


And inside App2 we've referenced Sensor as a FK using 'app1.Sensor'

#app2 > models.py

class Measurement(models.Model):
    device = models.ForeignKey('app1.Sensor')
    ....


Now if we try to reference that model in App2 > admin.py.
We're getting:   ...app1.Sensor has not ForeignKey to app2.Measurement...

#app2 > admin.py

from app1 import models as app1_models
 
class SensorInline(admin.TabularInline):
    model = app1_models.Sensor


How to add as an Inline a FK from another app?


Thanks in advance.
Reply all
Reply to author
Forward
0 new messages