Here's what my models.py looks like in its most simplified form:
from django.db import models
class Device(models.Model):
description = models.CharField(max_length=30)
ignored = models.BooleanField()
class Mac(models.Model):
mac = models.CharField(max_length=17, primary_key=True)
device = models.ForeignKey('Device')
class SeenEvent(models.Model):
mac = models.ForeignKey('Mac')
date = models.DateTimeField()
In the SeenEvent
model, I record times when a particular MAC address was seen. A Unix daemon scans the network periodically and then adds SeenEvent
objects to the database.
I'd like to generate a report of which Devices (or MAC address) were seen in the last - for example - 10 minutes (the "timeout" period). For these devices, I'd also like to specify when were the latest streak of events started - i.e. when was the latest first appearance of the device. Can I achieve that without pulling all SeenEvents for the given MACs?
One of my ideas relied on creating streak_id in SeenEvent
- before adding a new event, the Unix daemon would see when was the last time that the Mac was seen and - if it happened more than 10 minutes ago, assign a new *group_id* counter for the newly created event. Is that a good idea?