[Fixed]-Correct Usage of Django Related Fields

1👍

The issue, as it mentions is because of the reverse relationship. You need to add the related_name attribute

class Route(models.Model):                                                                                                  
    start_accom = models.OneToOneField(                                                                                     
        Accommodation,                                                                                                      
        on_delete=models.CASCADE,                                                                                           
        primary_key=True, 
        related_name="accommodation_start"                                                                                                  
    )                                                                                                                       
    end_accom = models.OneToOneField(                                                                                                                                                                             
        Accommodation,                                                                                                      
        on_delete=models.CASCADE,                                                                                           
        related_name="accommodation_end"                                                                                                  
    )                                                                                                                       
    mode_of_travel = models.CharField(max_length=50)                                                                        
    description = models.TextField()  

Leave a comment