[Fixed]-Get the function from the model in the template

1👍

You call it just like you have done, except that you don’t have anything called instance in the template. You have a for loop that assigns each element to a variable called cv, so you should use that.

style="width: {{ cv.get_relative_length }}px;
       height: {{ cv.get_relative_length }}px;
       margin-left: -{% widthratio cv.get_relative_length 2 1 %}px;
       margin-top: -{% widthratio cv.get_relative_length 2 1 %}px;
       "

0👍

models

  def get_longest_post(self):
        """
        Get the post object with the longest duration
        Returns: longest (amount of months)
        """
        longest = 0
        **for post in CreateCV.objects.all():**

            if post.active_post:
                d2 = datetime.now()
            else:
                d2 = post.end_date

            diff = self.get_month_diff(post.start_date, d2)

            if diff > longest:
                longest = diff

        return longest

Leave a comment