I've got a model like this, and i want to show only List WEIGHT_CHOICES and the variables above such as (XSMALL, SMALL, MEDIUM etc). But when i have no idea what queryset should i make. Because when i put MyAnimal.objects.all() it shows me what i want, but it shows me it (if there are 100 instances in db) 100 times. Do you know how can i either get only one instance or just those choices as json file?
class MyAnimal(models.Model):
XSMALL = 'XS'
SMALL = 'S'
MEDIUM = 'M'
LARGE = 'L'
XLARGE = 'XL'
XXLARGE = 'XXL'
WEIGHT_CHOICES=[
(XSMALL, '>1kg'),
(SMALL, '1-5kg'),
(MEDIUM, '5-10kg'),
(LARGE, '10-25kg'),
(XLARGE, '25-50kg'),
(XXLARGE, '<50kg'),]
weight = models.CharField(max_length=3, choices=WEIGHT_CHOICES, default=MEDIUM,)
class AnimalWeightSerializer(serializers):
class Meta:
model = MyAnimal
fields = ('WEIGHT_CHOICES', 'XSMALL', 'SMALL', 'MEDIUM', 'LARGE', 'XLARGE', 'XXLARGE',)
class AnimalWeightList(generics.ListAPIView):
queryset = MyAnimal.objects.all()
serializer_class = AnimalWeightSerializer