Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5955385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:06:24+00:00 2026-05-22T18:06:24+00:00

I have a php app that I am considering rewriting in either Django or

  • 0

I have a php app that I am considering rewriting in either Django or Rails (have done some maitence work over the years but not that familiar with issues like this). Ideally, I’d like to db schema as close as possible to what I’m using. It has a model this is like the following:

menu – id, name
menu_headers – id, menu_id, parent_menu_header_id, sort, name

The logic in the getMenu($id) function is to get the menu by the id and then get the menu_headers with corrent menu_id and a parent_menu_header_id of 0. There is a sub-menu function that gets called that gets submenus based upon the parent_menu_header_id. In other words, 0 means it is a root menu_header (ie select * from menu_headers where menu_id=$menu_id and parent_menu_header_id=0 order by sort). This all gets pushed to memcache so performance is not a concern.

I’m considering moving the app to django and am investigating how difficult / possible this would be.

I currently have:

class Menu(models.Model):
    location=models.ForeignKey(Location)
    name = models.CharField(max_length=200)

class Menu_Header(models.Model):
    menu=models.ForeignKey(Menu)
    parent=models.ForeignKey('self',null=True,blank=True,related_name="children")

A couple of issues have come up. It isn’t a true foreign key relationship. It looks like composite foreign keys are not supported. Maybe using something like a Root_Menu_Header which does have a true fk relationship. Is there a better way to model this? I have looked at the django-mptt but think that this should be possible. Any ideas?

thx

–edit #2

I’m probably not getting what you’re saying but for example I currently have:

menu   
id    name  
1     test menu  

menu_header  
id  menu_id parent_id   name  
1   1       NULL        Wine  
2   1       1           Red  
3   1       1           White  

When I get the Menu object, it has all 3 menu headers at the same level. So this clearly isn’t working correctly. Should I be manipulating this at the view level then? Or should the foreign key (menu_id) not be set in the menu_header table? Sorry for confusion but will be a lot of help to figure this out. If any suggestions on whether better to do this in Rails, that would also be appreciated.

thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:06:25+00:00Added an answer on May 22, 2026 at 6:06 pm

    Django expects that if a foreign key is not NULL, that it maps up to a real object. You’re not really going to be able to get around that. However, the absence of a value for parent (NULL) implicitly implies there is no parent, and you’ll find that developing the app around this will be quite natural.

    The only real problem I see is if you’re trying to use the existing database (or migrating data there from). In which case, you’ll only need to run a SQL update and set parent to NULL wherever it’s 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a traditional RDBMS based PHP app that I need to convert over
I have a PHP app that creates a CSV file which is forced to
I have a simple PHP app that prints 'hello world'. When I run it
I have a legacy PHP/MySQL app that calls mysql_connect(). Tons of existing downstream code
If I have in my php app an object that connects to the database,
I have written a small chat app that uses mysql + php to facilitate
I'm writing a simple web app in PHP that needs to have write access
In my (PHP) web app, I have a part of my site that keeps
So I have this php web app, and one of my folder contains some
I have a Windows/Apache2/PHP app that receives file using chunked encoding. The reason is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.