0

I have following django models:

SALAMI_TYPES = (
    ('S', 'Spicy'),
    ('R', 'Regular')
)
CHEESES = (
    ('P', 'Parmesan'),
    ('C', 'Cheddar')
)
class Pizza(models.Model):
    size = models.IntegerField()
    class Meta:
        abstract = True

class Pepperoni(Pizza):
    salami = models.CharField(max_length=1, choices=SALAMI_TYPES)

class ExtraCheese(Pizza):
    cheese = models.CharField(max_length=1, choices=CHEESES)

And following questions:

  1. How to iterate thought different types of pizzas? For example in menu template.
  2. Where to store forms for each pizza type and how to connect them to a model.

Thanks.

Harry Harrison
  • 591
  • 4
  • 12
foo
  • 275
  • 2
  • 17
  • 1
    Your question has to be more concrete. You can find answers for your questions just by going trough Django tutorial. – pythad Nov 15 '15 at 16:35

1 Answers1

2

You can do this by interrogating the python class hierarchy:

How can I find all subclasses of a class given its name?

In your case you would want to get all subclasses of 'Pizza', something like this:

Pizza.__subclasses__()
Community
  • 1
  • 1
Harry Harrison
  • 591
  • 4
  • 12