Skip to content

Instantly share code, notes, and snippets.

@benmcnelly
Created May 19, 2011 15:30
Show Gist options
  • Save benmcnelly/981030 to your computer and use it in GitHub Desktop.
Save benmcnelly/981030 to your computer and use it in GitHub Desktop.
FROM MODEL
class Item(models.Model):
title = models.CharField(max_length=128)
photo = models.ImageField(upload_to="photos/",null=True, blank=True,)
description = models.TextField(null=True, blank=True,)
section = models.ForeignKey(Section)
order = models.IntegerField(null=True, blank=True,)
creation_date = models.DateTimeField(auto_now_add=True)
last_modified = models.DateTimeField(auto_now=True)
active = models.CharField(max_length=21, choices=ACTIVE_CHOICES,null=True, blank=True)
# def get_full_path(request):
# full_path = ('http', ('', 's')[request.is_secure()], '://', request.META['HTTP_HOST'], request.path)
# return ''.join(full_path)
@models.permalink
def get_absolute_url(self):
return ('item_detail', (), { 'item_id': self.id })
def __unicode__(self):
return self.title
FROM VIEW
def item_detail(request, item_id, template_name='menu/detail.html'):
item = Item.objects.get(id=item_id)
return render_to_response(template_name, {"item":item},
context_instance=RequestContext(request))
FROM URLS
(r'^menus/$', 'menu.views.menu_list'),
(r'^menus/(?P<menu_name>[-\w]+)/$', 'menu.views.section_list'),
(r'^menus/(?P<menu_name>[-\w]+)/(?P<section_name>[-\w]+)/$', 'menu.views.item_list'),
(r'^menus/[-\w]+/[-\w]+/(?P<item_id>[-\w]+)/$', 'menu.views.item_detail'),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment