K
K
krasdev2020-02-26 16:10:36
Django
krasdev, 2020-02-26 16:10:36

Is it possible to do feedback on ForeignKey models?

Help me understand

There are 2 models connected via ForeignKey

class Company(models.Model
 ..
 
class Man(models.Model):
     company=models.ForeignKey('Company' ....)


How can I make a connection with the Man model from the Company model (with existing records)
So far, I found it only through inline to connect the Man model to the Company - but there you can only create new ones and I couldn’t figure out how to choose existing ones

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Sviridov, 2020-02-26
@dimuska139

Yes, you can

class Man(models.Model):
     company=models.ForeignKey('Company', related_name='mans')
...
Company.objects.get(id=1).mans

K
krasdev, 2020-02-26
@krasdev

But how can you insert Company.object.get(id=1).mans so that in the admin panel in the Company model you can select records from the Man model?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question