I’m studying about python /Jango and I came across a from and an import called "Rating" could someone explain to me what it’s for?

Asked

Viewed 26 times

0

def show_scoring_average(self):
    from .Rating import Rating   # Gostaria de entender esta linha
    try:
        ratings = Rating.objects.filter(user_rated = self.user).aggregate(Sum('value'), Count('user'))
        if ratings['user__count'] > 0 :
            scoring_average = ratings['value__sum'] / ratings ['user__count']
            scoring_average = round(scoring_average,2)
            return scoring_average
        return 'Sem avaliações'
    except:
        return 'Sem Avaliações'
  • 1

    **from .Rating import Rating** is written anyway or Voce added the *?

  • I added the **

  • 1

    You are importing a module called Rating and inside delete taking the Rating. So in the same folder of this script you probably have a file Rating.py and inside it seems to have a class (model Django think) with the name Rating (something like class Rating).

  • 1

    within this function called show_scoring_average(self): there is an import that could be outside it... this import is from a model... a model matching the database assignments... and a filter that selects a particular item

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.