Why not do this:
class Polygon(models.Model):
sides = models.IntegerField()
side_length = models.IntegerField()
def perimeter(self):
return sides * side_length
(Forgive the syntax. I'm a bit rusty.) This doesn't help with
irregular polygons, but with your example, it
Let's say I have a Polygon model
class Polygon(Models.model):
side_length = models.IntegerField()
Depending on the view I'm in, I want to calculate the perimeter of the
polygons as a square, or as a triangle (or anything other polygon).
What I'd like to do is somehow create a subclass of
2 matches
Mail list logo