Im a bit confused on how to carry on with my project, some guidance required
Inventory model have Equipment, TechFloat
I would like to get a query result on how many and what type of equipments checked out today, this week, this monthâŚ
class TechFloat(BaseModel):
emp = models.ForeignKey(Employee, related_name='float_owner', on_delete=models.DO_NOTHING)
equ = models.OneToOneField(Equipment, related_name='float_equipment', on_delete=models.DO_NOTHING)
installed = models.BooleanField(_("Installed"), default=False)
class Equipment(BaseModel):
class Stat(models.IntegerChoices):
LOST = 0, "Missing"
WAREHOUSE = 1, "Warehouse"
TECHFLOAT = 2, "Tech"
INSTALLED = 3, "Installed"
RETURN = 4, "Return"
serial = models.CharField(max_length=128, unique=True)
stat = models.PositiveSmallIntegerField(choices=Stat.choices, default=Stat.WAREHOUSE)
cpe = models.ForeignKey(cpeEquipment, related_name='cpeEquipment', on_delete=models.CASCADE)
currently I can get some count but nowhere what Im looking for and out of ideas how to proceed with it
def get_queryset(self):
today_start = timezone.now().replace(hour=0, minute=0, second=0)
today_end = timezone.now().replace(hour=23, minute=59, second=59)
self.cpe_result = TechFloat.objects.filter(created_at__gte=today_start, created_at__lte=today_end) \
.values('equ__cpe') \
.annotate(count=(Count('equ__cpe'))) \
.values('equ__cpe')
return self.cpe_result
<QuerySet [{'equ__cpe': 14}, {'equ__cpe': 3}, {'equ__cpe': 9}, {'equ__cpe': 7}, {'equ__cpe': 1}, {'equ__cpe': 5}, {'equ__cpe': 2}, {'equ__cpe': 15}, {'equ__cpe': 11}, {'equ__cpe': 8}]>
What I would like to have as output is the following.
<QuerySet [{'emp':132, {'equ__cpe': 14}, {'equ__cpe': 3}, {'equ__cpe': 9}}, {'emp':205, {'equ__cpe': 7}, {'equ__cpe': 1}, {'equ__cpe': 5}}, {'emp': 27, {'equ__cpe': 2}, {'equ__cpe': 15}, {'equ__cpe': 11}, {'equ__cpe': 8}}]>
The table I like to have as output:
John Doe: XU6 14 piece, XIONE 3 piece, CGM_2250 9 piece
Jim Prentis: XU6 7 piece, XIONE 1 piece, ART20 5 piece
Jeff Gogan: XU6 2 piece, XIONE 15 piece, ART20 11 piece, PID10 8 piece