I was trying to create some models similar to that of the basic
example "Polls" application.  Except instead of Polls and Choice, it
would be Menu and MenuItem.

I have the following in my models:
from django.db import models

# ----------
# Menu Class
# ----------

class Menu(models.Model):
  name = models.CharField(verbose_name="Name of the Menu", core=True,
maxlength=200)
  description = models.CharField(maxlength=200, help_text="Description
of the menu")
  slug = models.SlugField(prepopulate_from=('name',))
#  last_editied = models.

  class Admin:
    pass
  list_filter = ['name',]
  search_fields = ['name',]

  # ---------
  # Accessors
  # ---------

  #String method
  def __str__(self):
    return self.name

  #Method to return absolute urls
  def get_absolute_url(self):
    return "/menu/%i/" % (self.id)

  #Method to return menu description
  def get_description(Self):
    return self.description

  #Method to return slug
  def get_slug(self):
    return self.slug



# ---------------
# Menu Item Class
# ---------------

class MenuItem(models.Model):
  menu = models.ForeignKey(Menu, core=True, verbose_name="Menu belongs
to", edit_inline=models.TABULAR, num_in_admin=10,
num_extra_on_change=5)
  name = models.CharField(verbose_name="Name of the dish", core=True,
maxlength=200)
  description = models.CharField(verbose_name = "Menu item
description", maxlength=200)
  vegetarian = models.BooleanField(help_text="Is this dish
vegetarian?")
  price = models.FloatField(max_digits=5, decimal_places=2,
help_text="Price of dish, e.g. 13.75")

  # ---------
  # Accessors
  # ---------

  #String method
  def __str__(self):
    return self.name

  #Method to return parent menu
  def get_parent_menu(self):
    return self.menu

  #Method to return description
  def get_description(self):
    return self.description

  #Method to return vegetarian
  def get_vegetarian(self):
    return self.vegetarian

  #Method toreturn price
  def get_price(self):
    return self.price


I checked my DB and for somereason the MenuItem's are not being saved
when I save a menu??

Also my get_absolute_url method on Menu only returns ".../Menu/"
rather then ".../Menu/id"

Could someone please show me what I'm doing wrong?

Thanks,
Duncan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to