Answer the question
In order to leave comments, you need to log in
How to create a function call button in a django template?
There is a model:
class TreeNode(MPTTModel):
account = models.OneToOneField(User, unique=True, verbose_name='Аккаунт', related_name='treenode')
def request_cash_in(self):
if self.available_for_cash_in > 0:
from payments.models import CashingInRequest
CashingInRequest.objects.create(total=self.available_for_cash_in, client=self, date=date.today())
Answer the question
In order to leave comments, you need to log in
Well, how can you imagine it? There are two methods.
Synchronous. Create a separate view that calls the mentioned function and point that button to its URL. After calling the function, it can redirect the user to the right place.
AJAX - no page reload. Again, you are creating a separate view that is called by a JavaScript function that is called when the button is clicked.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question