Я пытаюсь создать приложение для бронирования отелей, используя django. Пытаюсь присоединиться к моим моделям на основе полей внешнего ключа. Список моих моделей ниже.
class RoomType(models.Model):
id = models.AutoField(primary_key=True)
type = models.CharField(max_length=100)
maxno = models.CharField(max_length=100)
area = models.CharField(max_length=100)
bed_no = models.CharField(max_length=100)
description = models.TextField(max_length=15000, blank=True, null=True)
popularity = models.DecimalField(max_digits=20, decimal_places=2, default=Decimal('0.00'))
class Meta:
db_table = "roomtypes"
verbose_name_plural = "Room Types"
class Room(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100, null=True)
hotel = models.ForeignKey(Hotel,on_delete=models.CASCADE, related_name='hotel_room_names',blank=True, null=True)
roomtype = models.ForeignKey(RoomType,on_delete=models.CASCADE, related_name='hotel_room_type',blank=True, null=True)
price = models.DecimalField(max_digits=20, decimal_places=2, default=Decimal('0.00'))
floor = models.IntegerField(blank=True, null=True)
description = models.TextField(max_length=15000, blank=True, null=True)
popularity = models.DecimalField(max_digits=20, decimal_places=2, default=Decimal('0.00'))
class Meta:
db_table = "rooms"
verbose_name_plural = 'Rooms'
class Amenities(models.Model):
room = models.OneToOneField(Room, on_delete=models.CASCADE, primary_key=True)
tv = models.BooleanField(default=False)
pool = models.BooleanField(default=False)
parking = models.BooleanField(default=False)
library = models.BooleanField(default=False)
ac = models.BooleanField(default=False)
lift = models.BooleanField(default=False)
restaurant = models.BooleanField(default=False)
gim = models.BooleanField(default=False)
wifi = models.BooleanField(default=False)
class Meta:
db_table = 'amenities'
class RoomImage(models.Model):
id = models.AutoField(primary_key=True)
room = models.ForeignKey(Room,on_delete=models.CASCADE, related_name='hotel_names_for_images',blank=True, null=True)
image = models.ImageField(upload_to='room/%y%m%d', blank=True, null=True)
description = models.TextField(max_length=15000, blank=True, null=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
db_table = "roomimages"
verbose_name_plural = "Room Images"
Это мои модели. И мне нужны значения результата от каждой модели, перечисленные ниже
название, тип, отель из Room и Image, описание из RoomImage и все поля Amenties из модели Amennities в виде одного запроса. Является ли это возможным. Пожалуйста, помогите мне узнать.
Заранее спасибо