| Literally Everyone Else | Django |
|---|---|
| Model | Model |
| View | Template |
| Controller | View |
This is the data and all the rules applying to that data.
class ChipotleEntree(models.Model):
RICE_CHOICES = (
('WHT', 'White Rice')
('BRW', 'Brown Rice')
)
BEAN_CHOICES = (
('BLK', 'Black Beans')
('PIN', 'Pinto Beans')
)
TORTILLA_CHOICES = (
('FLR', 'Flour')
('WHT', 'Whole Wheat')
)
rice = models.CharField(max_length = 3, choices = RICE_CHOICES, default = 'WHT')
beans = models.CharField(max_length = 3, choices = BEAN_CHOICES, default = 'BLK')
tortilla = models.CharField(max_length = 3, choices = TORTILLA_CHOICES, null = True,
blank = True)
meat = models.ManyToManyField('Meat')
class Meat(models.Model):
name = models.CharField(max_length = 20)
| id | rice | beans | tortilla |
|---|---|---|---|
| 1 | White | Black | Flour |
| 2 | Brown | Pinto | Wheat |
| 3 | Brown | Black | Flour |
| id | meat |
|---|---|
| 1 | Chicken |
| 2 | Steak |
| 3 | Carnitas |
| 4 | Barbacoa |
| 5 | Sofritas |
| id | entree | meat |
|---|---|---|
| 1 | 2 | 1 |
| 2 | 1 | 3 |
| 3 | 1 | 2 |
Gives model data to the template and interprets the user's actions
def view_entree(request, entree_id):
entree = ChipotleEntree.objects.get(id = entree_id)
return render_to_response("entree.html",{"entree":entree})Displays model data and sends user actions to the view
<p>{{entree.rice}}}</p>
<p>{{entree.beans}}}</p>
<p>{{entree.tortilla}}}</p>
{% for meat in entree.meat %}
<p>{{meat.name}}</p>
{% endfor %}white rice
black beans
flour tortilla
carnitas
steak