models.py
class Club(models.Model):
league_names = models.ForeignKey(League, on_delete= models.CASCADE, 
related_name='club')
name = models.CharField(max_length=100)
logo = models.ImageField(upload_to='media/core', max_length=255, null=True, 
blank=True)
won = models.IntegerField()
draw = models.IntegerField()
lost = models.IntegerField()
goal_for = models.IntegerField()
goal_against = models.IntegerField()
club_position = models.IntegerField()

def CalcPoints(self):
return self.won*3 + self.draw


admin.py

class ClubAdmin(admin.ModelAdmin):
list_display = ['league_names', 'name', 'logo', 'won', 'draw', 'lost', 
'total_points', 'goal_for', 'goal_against', 'goal_diff']
readonly_fields = ('total_points', 'goal_diff',)

admin.site.register(Club, ClubAdmin)

total_points = property(CalcPoints)

def GoalDiff(self):
return self.goal_for - self.goal_against

goal_diff = property(GoalDiff)


def __str__(self):
return self.name

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8ccf9b0f-da36-470e-9489-a4edd264943a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to