Django Quick facts

What?

  • Model
  • View
  • Controller

DISclaimer:

this is django, which is a little different

Literally Everyone Else Django
Model Model
View Template
Controller View

Models

This is the data and all the rules applying to that data.

Title Text


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)


entree

id rice beans tortilla
1 White Black Flour
2 Brown Pinto Wheat
3 Brown Black Flour

Meat

id meat
1 Chicken
2 Steak
3 Carnitas
4 Barbacoa
5 Sofritas
id entree meat
1 2 1
2 1 3
3 1 2

Many to Many

Views

 

Gives model data to the template and interprets the user's actions

Title Text

 def view_entree(request, entree_id):
 	entree = ChipotleEntree.objects.get(id = entree_id)
 	return render_to_response("entree.html",{"entree":entree})

Template

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 %}

apps & Projects

Apps: modules of code that do things

Projects: contain apps and configurations for those apps.

 

Together these things make up a complete web application

 

Copy of TL:DR Talks

By Elise Heron

Copy of TL:DR Talks

  • 219