N
N
Nposk2020-02-05 06:29:19
Django
Nposk, 2020-02-05 06:29:19

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

2 answer(s)
D
Dimonchik, 2020-02-05
@dimonchik2013

input type hidden

N
Nposk, 2020-02-12
@Nposk

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 адреса

Can anyone suggest how to implement this correctly?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question