Hi i m trying to use class based views on my project.
I've read the documentation but i couldnt determine it well.
what i'm trying to do is just use simple list of items of selected menu.
i have 2 classes on my model. Menu and MenuItem. Menu corresponds of
food menu types of a cafe; like "wine menu" "beef menu" ... and MenuItem
is sub item of menus. like in "Wıne menu": "red wine" or "white wine" or
some other kind of wine. but i couldnt get the list of items in the
menu.here is my models views urls and template.
----------------------------------------------------
models:
----------------------------------------------------
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from django.db import models
from photologue.models import Photo
class Menu(models.Model):
"""Model that contains the menu information\
such as wine menu, meat menu, vegetables menu"""
name = models.CharField(max_length=100, blank=True)
slug = models.SlugField(max_length=100)
description = models.CharField(max_length=200, blank=True)
def __unicode__(self):
return u'%s' %self.name
class Food(models.Model):
"""Model that contains the foods such as white wine,\
red wine, grilled meat, cooked meat."""
name = models.CharField(max_length=100)
menu = models.ForeignKey(Menu)
price = models.FloatField()
photo = models.ForeignKey(Photo)
def __unicode__(self)
return u'%s' %self.name
----------------------------------------------------
urls:
----------------------------------------------------
(r'^menu/(\w+)/$', FoodsListView.as_view()),
----------------------------------------------------
views:
----------------------------------------------------
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from menus.models import MenuItem, Menu
from django.shortcuts import render_to_response, get_object_or_404
from django.views.generic import ListView
class FoodsListView(ListView):
context_object_name = "foods"
template_name = "menu.html"
model = Food
def get_queryset(self):
self.menu = Food.objects.filter(menu__iexact=????????????)
return MenuItem.objects.filter(menu=self.menu)
----------------------------------------------------
template:
----------------------------------------------------
% extends "base.html" %}
{% block title %}Menu name{% endblock title %}
{% block extra_head %}
<link rel="stylesheet" href="{{STATIC_URL}}css/menu.css" />
{% endblock extra_head %}
{% block content %}
{% for food in foods %}
{{food}}
{% endfor %}
{% endblock %}
----------------------------------------------------
--
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.