Answer the question
In order to leave comments, you need to log in
django models. How to make a reference in a model field to the value of a field of another model?
Model structure:
class Profile (models.Model):
user = models.ForeignKey(MyUser)
university = models.CharField(max_length=512)
#...
class Stream (models.Model):
#...
class Enty (models.Model):
stream = models.ForeignKey(Stream)
entry = (max_length=512)
...
class Enty (models.Model):
stream = models.ForeignKey(Stream)
entry = (max_length=512)
university = #ссылка на Profile.university
...
Answer the question
In order to leave comments, you need to log in
It's not very clear what you want to reference in your schema if you have a one-to-many user - profile relationship. But even if the user field in the Profile would be OneToOneField, I’m not sure right off the bat that it’s possible to catch up with university from Profile in one request through the Dzhang orm. In pure SQL, one could write a query by joining Entry and Profile by user_id.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question