Reputation: 159
Using django
I have created two classes, but I have a problem in relation between tables and selecting rows:
class ayoub (models.Model):
name=models.CharField(max_length=200)
sname=models.CharField(max_length=200)
class sabri(models.Model):
a=models.ForeignKey(ayoub, on_delete=models.CASCADE)
name=models.CharField(max_length=200)
sname=models.CharField(max_length=200)
I want to display all the attributes of sabri
with the attribute name from class ayoub
not the primary key (id)
Upvotes: 0
Views: 644
Reputation: 27513
sabri.objects.filter(a__name='something').values('name','sname')
if you need name and sname from ayoub class you can try this query
sabri.objects.filter(a__name='something').values('name','sname','a__name','a__sname')
Upvotes: 1