get value price when select product in forms

I have tow models
class Detail(models.Model):
libelle = models.CharField(max_length=100)
qte = models.FloatField()
ressource = models.ForeignKey(Ressource, on_delete=models.CASCADE)
class Ressource(models.Model):
code= models.CharField(max_length=100)
libelle = models.CharField(max_length=100)
** price= models.FloatField**()

i need in my form sublit when i select ressource get value of price from Ressource table

You access data through a relationship using the object reference notation.

Assuming you have an object of type Ressource named a_ressource, then the price field is referenced as a_ressource.price.

If you have an object of type Detail named a_detail, then the related resource would be accessed as a_detail.ressource.

Put those two concepts together, then given an object of type Detail named a_detail, the price for a_detail can be accessed as a_detail.ressource.price.

thanks a lot for your replay
but i need for exemple to create a detail when i change the ressourcei get the price from table ressource
ressource is referenced in the table detail, so if i put a_detail.ressource.price . it get nothing like showing in the image bellow.

Ok, so you want to update your form after it has already been rendered and sent to the browser - that’s a completely different issue.

The easiest way to do this is to create a view to return the price when given a “Ressource”. Then you’ll write some JavaScript to detect when the “Ressource” select box has been changed, make an AJAX call to that new view, and use the response to update the page.

do you have an exemple because I’m filling blocked front this issue