first of all, I am very new to django and thank you for patience, I want to make web site for showing how the league stands and shows the particular team's footballer here what I have done so far
models.py
class League(models.Model):
name = models.CharField(max_length=255)
country = models.CharField(max_length=255)
founded = models.DateField()
def __str__(self):
return self.name
class Team(models.Model):
league = models.ForeignKey(
League, blank=True, null=True, on_delete=models.CASCADE)
image = models.ImageField(
upload_to="images/", default='images/Wolves.png', blank=True, null=True)
name = models.CharField(max_length=255)
win = models.IntegerField(blank=True, null=True)
draw = models.IntegerField(blank=True, null=True)
loss = models.IntegerField(blank=True, null=True)
scored = models.IntegerField(blank=True, null=True)
conceded = models.IntegerField(blank=True, null=True)
founded = models.DateField(blank=True, null=True)
games = models.IntegerField(blank=True, null=True)
point = models.IntegerField(blank=True, null=True)
average = models.IntegerField(blank=True, null=True)
class Meta:
ordering = [
'-point', '-average'
]
def __str__(self):
return self.name
def save(self, *args, **kwargs):
self.games = self.win + self.draw + self.loss
self.point = self.win*3 + self.draw
self.average = self.scored - self.conceded
super(Team, self).save(*args, **kwargs)
it would be great if I utilize from slug item instead of id To make easy understand of which league you are in
urls.py
urlpatterns = [
path('', home, name='home'),
path(r'^/league/(?P<id>\d+)/$', LeagueListView.as_view(), name='league'),
In order to learn what class based views is I should use them somehow once clicked in th base.html 's navbar, it should filter related league's teams
views.py
class LeagueListView(ListView):
model = Team
template_name = "league.html"
context_object_name = "teams_of_league"
# def get_queryset(self, request, *args, **kwargs):
# HERE I want to get teams of specific league and send to the league.html
base.html
<ul class="navbar-nav me-auto">
<li class="nav-item active">
<a class="nav-link" href="{% url 'league' specific_teams %}">Premier League</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="{% url 'league' specific_teams %}">La liga</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="{% url 'league' specific_teams %}">League 1</a>
</li>
</ul>
league.html
in this file there are table for corresponding league including teams informations
Thank you in advance
