I want to make a view model class in Django whose main purpose is only to display data in templates. like I have an auction model which has the following properties:
class Auction(models.Model):
seller = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(max_length=500)
description = models.CharField(max_length=4000)
edit_token = models.CharField(max_length=500)
starting_price = models.DecimalField(max_length=30, max_digits=19, decimal_places=2)
bid_price = models.DecimalField(max_length=30, max_digits=19, decimal_places=2, null=True)
winner_id = models.IntegerField(null=True)
end_date = models.DateTimeField(blank=True)
status = models.CharField(max_length=15, choices=STATUS__CHOICES, default='Active')
revision = models.IntegerField(default=1)
Now I only want to show title, description, starting_price etc to view and main purpose of the view model is I want to change the value of starting_price based on user currency selection so I wanted to add some business logic during the transformation of Database Model class to Template Model class.
Can I use form models or are there any other models I can use?
Aucun commentaire:
Enregistrer un commentaire