0

I'm building a web crawler contain links blogs etc of x website ... , I have field called number_of_crawled_Links and I want to make the value of that filed is the number of rows in another model Where Links Stored i want the process to be automatically without making request any idea how to do that

urek mazino
  • 130
  • 12

1 Answers1

0

You cannot do that in fields directly, but it's good idea to do that as a method.

class ModelA(models.Model):
    some_field = models.TextField()

class ModelB(models.Model):
    model_a = models.ForeignKey(ModelA, on_delete=models.CASCADE)

    def get_some_field_value(self):
        return self.model_a.some_field

Then ModelB can get dynamically the value of ModelA field some_field. You can do it with any type of values.

NixonSparrow
  • 6,130
  • 1
  • 6
  • 18
  • somone closed my question and refer me to a useless answser, however i want omake that work automaticly every 10 minutes for examlple – urek mazino Feb 05 '22 at 17:32
  • I do not want field value but the count of all rows in another table ( model) – urek mazino Feb 05 '22 at 17:43
  • You can do anything in such method and return whatever you like. I don't know the details, so I cannot give you ready code. Share more related code or figure out the rest yourself. And for `cron` you have to get something like `django-scheduler` and put it in your `AppConfig`. – NixonSparrow Feb 05 '22 at 17:44