Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Db not being populated for foreignkey [RSS Feed]

#1 March 9, 2008 13:06:54

D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Db not being populated for foreignkey


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 =
search_fields =

# ---------
# 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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#2 March 9, 2008 14:35:11

Nick F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Db not being populated for foreignkey


DuncanM wrote:
> 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
>
This might be off the mark, but I thought I'd check. The first thing
that comes to mind is database syncing. Did you remember to run
./manage.py syncdb after making those changes in the code?

Nick

--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#3 March 9, 2008 14:44:31

D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Db not being populated for foreignkey


Yeah, I've done that, I actually created the models at the same time
so they were all created at once.

On Mar 9, 1:35 pm, Nick Fishman <> wrote:
> DuncanM wrote:
> > 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
>
> This might be off the mark, but I thought I'd check. The first thing
> that comes to mind is database syncing. Did you remember to run
> ./manage.py syncdb after making those changes in the code?
>
> Nick
--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#4 March 9, 2008 14:46:40

D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Db not being populated for foreignkey


Just to clear up if its not obvious already. In the admin section
when I add a new Menu, I get the MenuItems shown below to add, just
when I click the save button it does not save them to the DB, but it
does save the menu created.
--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

  • Root
  • » Django
  • » Db not being populated for foreignkey [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support