33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from django.db import models
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from .exercises import Exercises
|
|
|
|
|
|
class FrequentCustomers(models.Model):
|
|
customer_id = models.BigAutoField(primary_key=True)
|
|
name = models.CharField(max_length=100, help_text='Last name', verbose_name=_("name"))
|
|
firstname = models.CharField(max_length=100, help_text='First name', verbose_name=_("firstname"))
|
|
email = models.CharField(max_length=100)
|
|
date_add = models.DateField()
|
|
#exercises = models.ManyToManyField(Exercises)
|
|
|
|
#def exercises(self):
|
|
# exercises = Exercises.objects.filter(customer__customer_id=self.customer_id)
|
|
# return exercises
|
|
|
|
@property
|
|
def exercise_count(self):
|
|
count = Exercises.objects.filter(customer__customer_id=self.customer_id).count()
|
|
return count
|
|
|
|
class Meta:
|
|
db_table = 'customer'
|
|
verbose_name = _("Frequent Customer")
|
|
verbose_name_plural = _("Frequent Customers")
|
|
#ordering = ['exercise_count']
|
|
#filter(exercise_count__gt=10)
|
|
|
|
def __str__(self):
|
|
return self.name
|