Re: Hierarchy Model

2012-07-15 Thread Setiaman Lee
Hi All,

It works by blocking it with the single quote. :)
Thanks for the help.

Cheers,
Setiaman
On Jul 16, 2012 2:44 AM, "yarko"  wrote:

>
>
> On Sunday, July 15, 2012 9:02:39 AM UTC-5, Setiaman wrote:
>>
>> Hi,
>>
>> I want to implement hierarchy data model which is quite common in
>> Relational Data Model.
>>
>> Let's say I have Employee model which has the relation to the boss which
>> link to the employee model itself.
>> It will look like this:
>>
>> class Employee(models.Model):
>> empname = models.CharField(max_length=**60)
>> boss = models.ForeignKey(Employee)
>>
>
> Employee is in the middle of being defined when you make this reference, so
> ... try something like:
>
> boss = models.ForeignKey('Employee')   # delayed evaluation
>
> or:
>
>boss = models.ForeignKey('self')  # I think this reads nicer
>
> See https://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey
>
>> salary = models.integer()
>>
>>
>> Sample Data:
>>
>> IDempname  bosssalary
>> --**
>> 1  albertnull  1
>> 2  bert  1  5000
>> 3  Chuck  1  5000
>> 4  Donna  3  3000
>> 5  Jack3  2000
>>
>> Albert is the root with Bert and Chuck under him and Chuck has Donna and
>> Jack under him.
>>
>> I got an error when I tried to sync to the database where Django telling
>> me that the employee is not exist in the Foreign key part.
>> Is there any way to manipulate this situation?
>>
>> Cheers,
>> Setiaman
>>
>
>
> Regards,
> Yarko
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/d5YolTy8ZO8J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Hierarchy Model

2012-07-15 Thread yarko


On Sunday, July 15, 2012 9:02:39 AM UTC-5, Setiaman wrote:
>
> Hi,
>
> I want to implement hierarchy data model which is quite common in 
> Relational Data Model.
>
> Let's say I have Employee model which has the relation to the boss which 
> link to the employee model itself.
> It will look like this:
>
> class Employee(models.Model):
> empname = models.CharField(max_length=60)
> boss = models.ForeignKey(Employee)
>

Employee is in the middle of being defined when you make this reference, so
... try something like:

boss = models.ForeignKey('Employee')   # delayed evaluation

or:

   boss = models.ForeignKey('self')  # I think this reads nicer

See https://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey

> salary = models.integer()
>
>
> Sample Data:
>
> IDempname  bosssalary
> --
> 1  albertnull  1
> 2  bert  1  5000
> 3  Chuck  1  5000
> 4  Donna  3  3000
> 5  Jack3  2000
>  
> Albert is the root with Bert and Chuck under him and Chuck has Donna and 
> Jack under him.
>
> I got an error when I tried to sync to the database where Django telling 
> me that the employee is not exist in the Foreign key part.
> Is there any way to manipulate this situation?
>
> Cheers,
> Setiaman
>


Regards,
Yarko 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/d5YolTy8ZO8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



RE: Hierarchy Model

2012-07-15 Thread lacrymol...@gmail.com

Put 'Employee' or if that fails, 'appname.Employee' with the quotes, as a 
string literal, this works for self-reference and reference loops. 

-Mensaje original-
De: Andre Terra
Enviados:  15/07/2012 13:30:05
Asunto:  Re: Hierarchy Model

I recommend using django-mptt. I can't link to it cause I'm writing on my
phone, but it's easy to find it on Google.

Also, your foreign key should target self rather than Employee, IIRC.

Cheers,
AT

-- Sent from my phone, please excuse any typos. --
On Jul 15, 2012 11:02 AM, "Setiaman Lee" <setiaman@gmail.com> wrote:

> Hi,
>
> I want to implement hierarchy data model which is quite common in
> Relational Data Model.
>
> Let's say I have Employee model which has the relation to the boss which
> link to the employee model itself.
> It will look like this:
>
> class Employee(models.Model):
> empname = models.CharField(max_length=60)
> boss = models.ForeignKey(Employee)
> salary = models.integer()
>
>
> Sample Data:
>
> IDempname  bosssalary
> --
> 1  albertnull  1
> 2  bert  1  5000
> 3  Chuck  1  5000
> 4  Donna  3  3000
> 5  Jack3  2000
>
> Albert is the root with Bert and Chuck under him and Chuck has Donna and
> Jack under him.
>
> I got an error when I tried to sync to the database where Django telling
> me that the employee is not exist in the Foreign key part.
> Is there any way to manipulate this situation?
>
> Cheers,
> Setiaman
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Hierarchy Model

2012-07-15 Thread Andre Terra
I recommend using django-mptt. I can't link to it cause I'm writing on my
phone, but it's easy to find it on Google.

Also, your foreign key should target self rather than Employee, IIRC.

Cheers,
AT

-- Sent from my phone, please excuse any typos. --
On Jul 15, 2012 11:02 AM, "Setiaman Lee"  wrote:

> Hi,
>
> I want to implement hierarchy data model which is quite common in
> Relational Data Model.
>
> Let's say I have Employee model which has the relation to the boss which
> link to the employee model itself.
> It will look like this:
>
> class Employee(models.Model):
> empname = models.CharField(max_length=60)
> boss = models.ForeignKey(Employee)
> salary = models.integer()
>
>
> Sample Data:
>
> IDempname  bosssalary
> --
> 1  albertnull  1
> 2  bert  1  5000
> 3  Chuck  1  5000
> 4  Donna  3  3000
> 5  Jack3  2000
>
> Albert is the root with Bert and Chuck under him and Chuck has Donna and
> Jack under him.
>
> I got an error when I tried to sync to the database where Django telling
> me that the employee is not exist in the Foreign key part.
> Is there any way to manipulate this situation?
>
> Cheers,
> Setiaman
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Hierarchy Model

2012-07-15 Thread Andre Terra
-- Sent from my phone, please excuse any typos. --
On Jul 15, 2012 11:02 AM, "Setiaman Lee"  wrote:

> Hi,
>
> I want to implement hierarchy data model which is quite common in
> Relational Data Model.
>
> Let's say I have Employee model which has the relation to the boss which
> link to the employee model itself.
> It will look like this:
>
> class Employee(models.Model):
> empname = models.CharField(max_length=60)
> boss = models.ForeignKey(Employee)
> salary = models.integer()
>
>
> Sample Data:
>
> IDempname  bosssalary
> --
> 1  albertnull  1
> 2  bert  1  5000
> 3  Chuck  1  5000
> 4  Donna  3  3000
> 5  Jack3  2000
>
> Albert is the root with Bert and Chuck under him and Chuck has Donna and
> Jack under him.
>
> I got an error when I tried to sync to the database where Django telling
> me that the employee is not exist in the Foreign key part.
> Is there any way to manipulate this situation?
>
> Cheers,
> Setiaman
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.