Answer the question
In order to leave comments, you need to log in
How to take from the linked table name, not id?
When outputting the Car table from the database, the id from the Manufacturer arrives in the car_brand field instead of the name. How to change it?
class Manufacturer(models.Model):
name = models.CharField(max_length=128, unique=True)
class Car(models.Model):
car_brand = models.ForeignKey(Manufacturer, on_delete=models.CASCADE,)
componentDidMount() {
axios
.get(getResourceURL("car"))
.then((result) => {
this.setState({
car: result.data
})
})
.catch((error) => console.log(error));
}
const Car = ({car}) => {
//{ console.log('car:', car);}
return (
<tr className="cars-list">
<td>
{car.id}
</td>
<td>
{car.car_brand}
</td>
<td>
<Link to={`/car/detail/${car.id}`} className="nav-link">
{car.model}
</Link>
</td>
<td>
{car.price}
</td>
<td>
{car.max_speed}
</td>
<td>
<Link to={`/cars/delete/${car.id}`} className="nav-link">
delete
</Link>
</td>
</tr>
)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question