MK15
asked on
Django - queryset containing foreign key reference
Hi,
How would i go about getting all the results from 2 tables that match foreign key to primary key?
SQL:- select * from company_room, company_property where company_room.property_id = company_property.id
Model.py
Forms.py
Thanks in advance,
MP
How would i go about getting all the results from 2 tables that match foreign key to primary key?
SQL:- select * from company_room, company_property where company_room.property_id = company_property.id
Model.py
class Property(models.Model):
street = models.CharField(max_length=100, blank=False)
city = models.CharField(max_length=100, blank=False)
class Room(models.Model):
room_number = models.IntegerField(blank=True)
property = models.ForeignKey(Property)
Forms.py
class RoomsForm(forms.ModelForm):
selection = ModelChoiceField(queryset=Room.objects.all())
class Meta:
model = Room
fields = "__all__"
Thanks in advance,
MP
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.