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
Asked
Active
Viewed 260 times
0
-
Does this answer your question? https://stackoverflow.com/questions/3652736/django-update-queryset-with-annotation/50134728 – Iain Shelvington Feb 05 '22 at 17:30
-
I don't think it is an answer to the question... – NixonSparrow Feb 05 '22 at 17:34
-
@Iain Shelvington it is not what I'm looking for , bcs i already updating it using mysql method but i wanna avoid this and use pure django – urek mazino Feb 05 '22 at 17:41
1 Answers
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