JOIN

23 views
Skip to first unread message

Abdou KARAMBIZI

unread,
Oct 25, 2023, 6:55:51 AM10/25/23
to django...@googlegroups.com
Hello group members,

How can I get result containing any information from both 3 models  

eg. 
 Customer|contact          | room number|room price| business|
------------- -------------------------------------------------------------------
John Doe |+1 989898989|12                 | 1000        |restaurant


class Room(models.Model):
room_id = models.AutoField(primary_key=True)
room_number = models.CharField(max_length = 200)
room_square_meters = models.IntegerField()
room_price = models.IntegerField()

def __int__(self):
return  self.room_number


class Customer(models.Model):
    customer_id = models.AutoField(primary_key=True)
    national_id = models.CharField(max_length=200)
    first_name = models.CharField(max_length=200)
    last_name = models.CharField(max_length=200)
    contact_number = models.CharField(max_length=200)
    customer_status = models.BooleanField(default=True)
   
    def __str__(self):
        return self.first_name+' '+self.last_name

class CustomerRooms(models.Model):
    room = models.ForeignKey(Room,on_delete=models.CASCADE)
    customer  = models.ForeignKey(Customer,on_delete=models.CASCADE)
    business = models.CharField(max_length = 200)


Reply all
Reply to author
Forward
0 new messages