django OneToOne reverse access

前端 未结 1 1577
忘掉有多难
忘掉有多难 2021-02-02 06:46

I have these simple classes

Class A(models.Model):
    ...

Class Meta(models.Model):
    a = models.OnetoOneField(A, primary_key=True)
    width = models.Intege         


        
1条回答
  •  北海茫月
    2021-02-02 07:03

    Define a related_name to call the reverse accessor.

    a = models.OneToOneField(A, related_name='foobar')
    # ...
    a.foobar 
    

    0 讨论(0)
提交回复
热议问题