[Answered ]-How do I Access fields from one table through another table in Django

1👍

You can simply use a ForeignKey in the Client model that refers to the Property model, like so:

class Property(models.Model):
    location = models.CharField(choices=Property_Location, max_length=120)
    building_type= models.CharField(choices=Property_Type, max_length=120)


class Client(models.Model):
    first_name = models.CharField(max_length=120)
    last_name = models.CharField(max_length=120)
    phone = models.IntegerField()
    property_f = models.ForeignKey(Property, on_delete=models.SET_NULL, null=True)

You can set any option on ForeignKey.on_delete according to your need.

Leave a comment