Good afternoon. Help me please. There is a project on Django. The project has a code from bootstrap4 - progress-bar, I need this progress bar, but I can't understand how to implement its performance, since it has data stored in percent, but I don't have percent, but the project date, that is, there is a beginning Let's say the project is 01 02 2000 and the end of the project 01 02 2002 there are 730 days difference between them. Here's how I turn these 730 days into 100%, and the remainder - let's say 140 days, also turn into percent.
HTML Template
<div class="progress">
<div class="progress-bar bg-success" role="progressbar" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
</div>
Python Template
prjauth = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name="")
prjtitle = models.CharField(max_length=200, verbose_name="")
prjdesc = models.TextField(verbose_name="")
prjfiles = models.FileField(upload_to='files_project', verbose_name="")
prjdatestart = models.DateTimeField(default=timezone.now, verbose_name="")
prjdateend = models.DateTimeField(blank=True, null=True, verbose_name="")
prjproekts = models.DateTimeField(blank=True, null=True, verbose_name="")
prjproekte = models.DateTimeField(blank=True, null=True, verbose_name="")
prjdatesnabs = models.DateTimeField(blank=True, null=True, verbose_name="")
prjdatesnabe = models.DateTimeField(blank=True, null=True, verbose_name="")
prjdatelines = models.DateTimeField(blank=True, null=True, verbose_name="")
prjdatelinee = models.DateTimeField(blank=True, null=True, verbose_name="")
You can add a method to your model which can return the date progress:
Class MyModel(models.Model):
# fields
def get_progress(self):
return timezone.now().date - self.start_date / self.end_date - self.start_date
The method can be called in your template:
aria-valuenow="{{ mymodel.get_progress }}"
Lastly, I would suggest removing the prj
prefix on your model fields as it makes it hard to read - presumably your model is already called something like Project - it would therefore be easier to read project.start_date
than project.prjstart_date
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.