Answer the question
In order to leave comments, you need to log in
How to make a "calculated" field in a Django model received from an external system?
There is a model which contains IP which is entered from the form. It is necessary to get additional information on IP (for example, MAC) and enter it into the form. Ideally, all external data should be received in the process of submitting the main form, and a confirmation page will appear with validation of the data entered and received.
Clarification:
The model is something like this
IP - charfield
MAC - charfield
IP is entered by hand, MAC is the result of executing the function based on the entered IP.
Answer the question
In order to leave comments, you need to log in
I'll try to answer myself, but there is a suspicion that this is not the correct answer
class Equipment(models.Model):
IP = models.CharField(max_length=15)
_MAC = models.CharField(max_length=30,db_column="mac")
@property
def mac(self):
return self._MAC
@mac.setter
def mac(self, value):
self._MAC= '%s ---- %s' % (self.IP, "111111111")
' это для примера, тут должна быть функция получения MAC адреса
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question