Reputation: 1
I am newbie for Django admin. I have made little site where I am giving option to user to upload some mp3 files.for that I am using Django file upload. I have html page for showing all those files where I have option to download it by clicking on download symbol. I want to count on every download. I have added filed in my table to keep it's record.
My html file where I want to count hit.
<th scope="row" style="vertical-align: middle;">
<a href="{{radio_file.audio_file.url}}" download >
<i class="fas fa-download mr-2 text-danger"></i></a>
</th>
<td>{{ radio_file.download_count }} </td>
models.py
class RadioFile(models.Model): audio_file = models.FileField( upload_to='radio/', validators=[validate_file_extension], max_length=255, help_text="Only wav,mp1,mp2,mp3,m4p,.m5p,wma and voc files are allowed.", )
category = models.ForeignKey(
Category,
related_name='radio_files',
on_delete=models.SET_NULL,
null=True,
)
trending = models.BooleanField(
default=False,
help_text="Tick if you want to show it on Home Page",verbose_name="Feature"
)
download_count = models.PositiveIntegerField(default=0, blank=False,null=False)
uploaded_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
related_name='radio_files',
on_delete=models.CASCADE,
)
uploaded_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
Upvotes: 0
Views: 111
Reputation: 1257
I have option to download it by clicking on download symbol
So everytime the download is successful write a post request to map item and downloadCount (a field) and increment the downloadCount everytime a download is successful.
Upvotes: 0