#Filtering and grouping data

29 messages · Page 1 of 1 (latest)

timid geode
#

I recently added the .values("ea_player_num") to the views.py file below. Why would I suddenly be getting 500 errors when I'm trying to load the page?

def goalies(request):
    all_goalies = GoalieRecord.objects.filter(game_num__season_num=seasonSetting).values("ea_player_num").annotate(
        goaliesgp = Count("game_num"),
        goaliesshots = Sum("shots_against"),
        goaliesga = (Sum("shots_against")-Sum("saves")),
        goaliessaves = Sum("saves"),
        goaliessvp = (Cast(Sum("saves"), models.FloatField())/Cast(Sum("shots_against"), models.FloatField()))*100,
        goaliesgaa = ((Cast(Sum("shots_against"), models.FloatField())-Cast(Sum("saves"), models.FloatField()))/Cast(Sum("game_num__gamelength"), models.FloatField()))*3600,
        goaliesshutouts =Sum(Case(
            When(shutout=True, then=1),
            default=0,
            output_field=models.IntegerField()
        )),
        goalieswins = Sum(Case(
            When(win=True, then=1),
            default=0,
            output_field=models.IntegerField()
        )),
        goalieslosses = Sum(Case(
            When(loss=True, then=1),
            default=0,
            output_field=models.IntegerField()
        )),
        goaliesotlosses = Sum(Case(
            When(otloss=True, then=1),
            default=0,
            output_field=models.IntegerField()
        )),
    ).order_by("ea_player_num")
    context = {
        "all_goalies": all_goalies, "scoreboard": get_scoreboard()
    }
    return render(request, "GHLWebsiteApp/goalies.html", context)```
chilly bramble
#

what's the stack trace say?

#

if you don't see one, try running in debug, with the debug toolbar activated

timid geode
chilly bramble
#

I suspect your django thinks it's in production

timid geode
#

Ah, good point, I'll try in debug now

chilly bramble
#

I'm not certain that the output of values is a queryset

timid geode
chilly bramble
#

that's the sorta thing you need to try out in the REPL

timid geode
#
In template /home/someuser/GHL-Website/GHLWebsiteDjango/GHLWebsiteApp/templates/GHLWebsiteApp/skaters.html, error at line 44
   Reverse for 'player' with arguments '('',)' not found. 1 pattern(s) tried: ['player/(?P<player>[0-9]+)/\\Z']
   34 :           <th>+/-</th>
   35 :           <th>HIT</th>
   36 :           <th>TOP</th>
   37 :           <th>BS</th>
   38 :           <th>PPG</th>
   39 :           <th>SHG</th>
   40 :         </tr>
   41 :         {% for player in all_skaters %}
   42 :         <tr>
   43 :           <td>{{ forloop.counter }}</td>
   44 :           <td><a href=" {% url 'player' player.ea_player_num.ea_player_num %} ">{{ player.ea_player_num.username }}</a></td>
   45 :           <td>{{ player.ea_player_num.current_team.club_abbr }}</td>
   46 :           <td>{{ player.skatersgp }}</td>
   47 :           <td>{{ player.skatersgoals }}</td>
   48 :           <td>{{ player.skatersassists }}</td>
   49 :           <td>{{ player.skaterspoints }}</td>
   50 :           <td>{{ player.skaterssog }}</td>
   51 :           <td>{{ player.skaterspims }}</td>
   52 :           <td>{{ player.skatersplusminus }}</td>
   53 :           <td>{{ player.skatershits }}</td>
   54 :           <td>{{ player.skatersposs|floatformat:1 }}</td>```
chilly bramble
#

player.ea_player_num.ea_player_num does indeed look odd

#

is your project public on github? If so, I can take a look

timid geode
chilly bramble
#

.oO("skater shits"? They put those in the stats?)

timid geode
timid geode
chilly bramble
#

it evaulates to the empty string (and not, say, an attribute error) because we're in template-land

timid geode
#

🤔

chilly bramble
#

what should I do to reproduce the error?

timid geode
#

Leaders, Skater Staas, or Goalie Stats at the top

chilly bramble
#

I've clicked them all; no errors. Maybe I need actual data

timid geode
#

Looks like you were right - I removed one of the ea_player_num from that line and it loaded

chilly bramble
#
[14/Mar/2025 20:39:23] "GET / HTTP/1.1" 200 5957
[14/Mar/2025 20:39:23] "GET /static/GHLWebsiteApp/mainstyle.css HTTP/1.1" 200 7133
[14/Mar/2025 20:39:23] "GET /static/GHLWebsiteApp/stock-user-photo.jpg HTTP/1.1" 200 9993
[14/Mar/2025 20:39:23] "GET /static/GHLWebsiteApp/sortable.js HTTP/1.1" 200 16878
[14/Mar/2025 20:39:23] "GET /static/GHLWebsiteApp/background.jpg HTTP/1.1" 200 411270
Not Found: /favicon.ico
[14/Mar/2025 20:39:23] "GET /favicon.ico HTTP/1.1" 404 6023
[14/Mar/2025 20:40:50] "GET /leaders/ HTTP/1.1" 200 8371
[14/Mar/2025 20:40:50] "GET /static/GHLWebsiteApp/sortable.js HTTP/1.1" 304 0
[14/Mar/2025 20:40:50] "GET /static/GHLWebsiteApp/mainstyle.css HTTP/1.1" 304 0
[14/Mar/2025 20:40:52] "GET /skaters/ HTTP/1.1" 200 2621
[14/Mar/2025 20:40:52] "GET /static/GHLWebsiteApp/mainstyle.css HTTP/1.1" 304 0
[14/Mar/2025 20:40:52] "GET /static/GHLWebsiteApp/sortable.js HTTP/1.1" 304 0
[14/Mar/2025 20:40:54] "GET /goalies/ HTTP/1.1" 200 2504
[14/Mar/2025 20:40:54] "GET /static/GHLWebsiteApp/sortable.js HTTP/1.1" 304 0
[14/Mar/2025 20:40:54] "GET /static/GHLWebsiteApp/mainstyle.css HTTP/1.1" 304 0
[14/Mar/2025 20:40:56] "GET /standings/ HTTP/1.1" 200 2932
[14/Mar/2025 20:40:56] "GET /static/GHLWebsiteApp/mainstyle.css HTTP/1.1" 304 0
[14/Mar/2025 20:40:56] "GET /static/GHLWebsiteApp/sortable.js HTTP/1.1" 304 0
timid geode
#

Easier fix than I thought it was going to be. Thanks bud!

chilly bramble
#

move to where the puck will be; not where it is

#

nods sagely