Здесь я упомянул мою модель, сериализатор и вид. На самом деле я новичок в этой концепции. Я не знаю, как получить последний добавленный товар.
Models.py
class Products(models.Model):
name = models.CharField(max_length=100)
image = models.CharField(max_length=100, null=True)
categories = models.ArrayModelField(
model_container=Category,
model_form_class=CategoryForm
)
specifications = models.ArrayModelField(
model_container=Specifications,
model_form_class=SpecificationsForm
)
description = models.CharField(max_length=1000)
reviews = models.ArrayModelField(
model_container=Reviews,
model_form_class=ReviewsForm
)
drizzly = models.BooleanField(default=False)
complete = models.BooleanField(default=False)
comment = models.CharField(max_length=500)
click_count = models.IntegerField()
serializer.py
class ProductsSerializer(serializers.ModelSerializer):
class Meta:
model = Products
fields = ('id',
'name',
'image',
'categories',
'specifications',
'description',
'reviews',
'drizzly',
'complete',
'comment',
'click_count')
views.py
class ProductsViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
queryset = Products.objects.all()
serializer_class = ProductsSerializer
Скажите, пожалуйста, как это сделать?