Модели
class Medicine(models.Model):
"""Прививки и тд"""
name = models.CharField("Имя", max_length=100)
def __str__(self):
return self.name
class Meta:
verbose_name = "Медицина"
verbose_name_plural = "Медицина"
class Dog(models.Model):
"""Собаки"""
class Thoroughbredness(models.TextChoices):
THOROUGHBRED = 'породистая', 'породистая'
CROSSBREED = 'помесь', 'помесь'
NOBREED = 'без породы', 'без породы'
class Gender(models.TextChoices):
MALE = 'мужской', 'мужской'
FEMALE = 'женский', 'женский'
class Size(models.TextChoices):
SMALL = 'малький', 'малький'
MEDIUM = 'средний', 'средний'
BIG = 'большой', 'большой'
name = models.CharField(max_length=200, db_index=True, verbose_name='Имя')
bdate = models.DateField()
@property
def get_age(self):
return (date.today()-self.bdate).days//30
description = models.TextField(blank=True)
breed_type = models.CharField(
max_length=12,
choices=Thoroughbredness.choices,
)
gender = models.CharField(
max_length=12,
choices=Gender.choices,
)
size = models.CharField(
max_length=12,
choices=Size.choices,
)
receipt_date = models.DateField()
peculiarities = models.TextField(blank=True)
medicine = models.ManyToManyField(Medicine, verbose_name="Медицина", related_name="dog_medicine")
small_img = models.ImageField(upload_to='mini_pets/%Y/%m/%d', blank=True)
slug = models.SlugField(max_length=200, db_index=True, unique=True)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('dog details', kwargs={'dog_slug': self.slug})
class Meta:
verbose_name = "Питомец"
verbose_name_plural = "Питомцы"
Вью
class DogoFilters:
"""поля фильтров"""
def get_ages(self):
return Dog.objects.values_list("bdate", flat=True).distinct('bdate')
def get_breed_type(self):
return Dog.objects.values_list("breed_type", flat=True).distinct('breed_type')
def get_gender(self):
return Dog.objects.values_list("gender", flat=True).distinct('gender')
def get_size(self):
return Dog.objects.values_list("size", flat=True).distinct('size')
def get_shelter_time(self):
#delta = datetime.now().date() - Dog.objects.values_list("receipt_date").distinct('receipt_date')
#return delta.month
return Dog.objects.values_list("receipt_date", flat=True).distinct('receipt_date')
def get_medical_information(self):
return Dog.objects.values_list("medicine", flat=True).order_by('medicine').distinct('medicine')
def get_medical_information(self):
return Dog.objects.values_list("medicine", flat=True).order_by('medicine').distinct('medicine')
Получаю айди по итогу, не могу достучаться до поля Medicine.name.