I think you can do something like this
stats = Statistics.objects.all().order_by('-last_update')
latest_stat = 0
for stat in stats:
print(abs(latest_stat - stat.followers))
latest_stat = stat.followers
On Mon, Jun 4, 2018 at 11:24 AM, Daniel Germano Travieso <danielgtravieso@gmail.com> wrote:
Hello!I don't quite understand what you mean by the followers difference by day, but as that difference by day is not a property of each model tuple, but a property of a specific day, you can write a view to handle that processing. Custom model Managers are used to either add manager methods or to customize and change the QuerySet your model returns. If you wish to use the model manager for this, it could be used to add a field to your model that makes a query to the last followers on that day and calculates the difference (?). You could also use a @property on your Model class for that too.Hope it helps![]'sDaniel Germano TraviesoEngenharia da Computação Turma: 013UnicampOn Thu, May 31, 2018 at 11:14 AM, João Paulo <joaopaulo.mailfs@gmail.com> wrote:--
Hey guys,I´m using SQLite and trying to calculate the followers difference by dayThis is my model:class Statistics(models.Model):followers = models.IntegerField()last_update = models.DateTimeField(auto_now_add=True) This are my database rows:"6" "50" "2018-05-29 00:25:48.276102"
"1" "100" "2018-05-29 00:26:48.276102""3" "200" "2018-05-30 00:27:04.178444""5" "250" "2018-05-30 00:30:04.178444""4" "300" "2018-05-31 00:27:04.178444"
And the result I´m tryting to achieve is:followers | last_update
150 2018-05-30
50 2018-05-31
# I´m new to Django and thinking about use a Manager, but don't know if´s doable using a Manager
# Does anyone has a suggestion ?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com .
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users .
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3196a628-a53f .-41ac-bcbf-6cc8b8a66016%40goog legroups.com
For more options, visit https://groups.google.com/d/optout .
To view this discussion on the web visit https://groups.google.com/d/--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com .
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users .msgid/django-users/ .CABF8kZNYHY8zWYNw3WKTxLMcnsxxD U9hPAep4wpzk9i4c-veRg%40mail. gmail.com
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAE-E-_0j3r6g-DHrhif9P_HhpKHCPDohuS6jn86_XPzcg4zFJA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment