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 polygon (that
doesn't create a new database table), such as a Square or Triangle,
and then after I pull a Polygon queryset out of the database, I'd like
to cast all the Polygons to either Squares or Triangles, and then I
can call the perimeter() method for that object:

class Square(Polygon)
    def perimeter(self): return 3*self.side_length
    class Meta: abstract=True

But what I've ended up doing is added a traingle_perimeter() and a
square_perimeter() method to the Polygon object, and it just doesn't
seem right. Is there a preferred pythonic / djangoistic way to do
this?

Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to