Re: error on models with foreign key on each other
It looks like your problem is that you have a ForeignKey pointing both ways... This is unnecessary. You only need one ForeignKey, pointing from the pointing from the 'child' to the 'parent'... I would guess from your snippet, that one employee can have many contracts and assignments so you need to delete these 2 lines: employee_contract = models.ForeignKey('EmployeeContract') employee_assignment = models.ForeignKey('EmployeeAssignment') Django ORM will add two properties to your model which will return a query set of all of an individual Employee's contracts or assignments. These properties (they're actually descriptors) will be called something like employeecontract_set, if you want to change this name put: employee = models.ForeignKey(Employee, related_name='contracts') or whatever you want to call the relationship... now you'll be able to do: >>>emp = Employee.objects.get() >>>emp.contracts.all() ... [.. ] Hope this explains it OK. Ben On 30/07/07, James Bennett <[EMAIL PROTECTED]> wrote: > > > On 7/29/07, james_027 <[EMAIL PROTECTED]> wrote: > > D:\private\james\documents\django\ksk>python manage.py validate > > manning.employee: Reverse query name for field 'employee_contract' > > clashes with field 'EmployeeContr > > act.employee'. Add a related_name argument to the definition for > > 'employee_contract'. > > manning.employee: Reverse query name for field 'employee_assignment' > > clashes with field 'EmployeeAss > > ignment.employee'. Add a related_name argument to the definition for > > 'employee_assignment'. > > 2 errors found. > > Django is telling you exactly what you need to do to resolve the > error. Look at the model documentation for "related_name" for more > details. > > > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of > correct." > > > > -- Regards, Ben Ford [EMAIL PROTECTED] +628111880346 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: error on models with foreign key on each other
On 7/29/07, james_027 <[EMAIL PROTECTED]> wrote: > D:\private\james\documents\django\ksk>python manage.py validate > manning.employee: Reverse query name for field 'employee_contract' > clashes with field 'EmployeeContr > act.employee'. Add a related_name argument to the definition for > 'employee_contract'. > manning.employee: Reverse query name for field 'employee_assignment' > clashes with field 'EmployeeAss > ignment.employee'. Add a related_name argument to the definition for > 'employee_assignment'. > 2 errors found. Django is telling you exactly what you need to do to resolve the error. Look at the model documentation for "related_name" for more details. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
error on models with foreign key on each other
Hi, I am trying to migrate an existing application to django. I am encountering the following problem with this models D:\private\james\documents\django\ksk>python manage.py validate manning.employee: Reverse query name for field 'employee_contract' clashes with field 'EmployeeContr act.employee'. Add a related_name argument to the definition for 'employee_contract'. manning.employee: Reverse query name for field 'employee_assignment' clashes with field 'EmployeeAss ignment.employee'. Add a related_name argument to the definition for 'employee_assignment'. 2 errors found. class Employee(models.Model): lastname = models.CharField(maxlength=30) firstname = models.CharField(maxlength=30) middlename = models.CharField(blank=True, maxlength=30) gender = models.CharField(maxlength=1) birthday = models.DateField() contact_no = models.CharField(blank=True, maxlength=50) address = models.CharField(maxlength=100) notes = models.CharField(maxlength=200) pay_by = models.CharField(maxlength=3, choices=PAY_BY_LIST) hour_rate = models.DecimalField(max_digits=7, decimal_places=2) allowance = models.DecimalField(max_digits=7, decimal_places=2) account_no = models.CharField(blank=True, maxlength=20) sss = models.CharField(blank=True, maxlength=20) phil_health = models.CharField(blank=True, maxlength=20) pag_ibig = models.CharField(blank=True, maxlength=20) employee_contract = models.ForeignKey('EmployeeContract') employee_assignment = models.ForeignKey('EmployeeAssignment') AREA_LIST = ( ('CKG', 'Cooking'), ('DLY', 'Delivery'), ('DYG', 'Drying'), ('FLA', 'Flavoring'), ('FYG', 'Frying'), ('LGS', 'Logistics'), ('MXG', 'Mixing'), ('PKG', 'Packaging'), ('ROG', 'Roasting'), ) class EmployeeAssignment(models.Model): employee = models.ForeignKey(Employee) assignment_from = models.DateField() assignment_to = models.DateField() area = models.CharField(maxlength=3, choices=AREA_LIST) position = models.CharField(maxlength=20) edit_by = models.ForeignKey(Profile) EMPLOYEE_CONTRACT_STATUS_LIST = ( ('ACT', 'Active'), ('FIN', 'Finnish'), ('RES', 'Resign'), ('TER', 'Terminate'), ) class EmployeeContract(models.Model): employee = models.ForeignKey(Employee) contract_to = models.DateField() contract_from = models.DateField() notes = models.CharField(blank=True, maxlength=200) status = models.CharField(maxlength=3, choices=EMPLOYEE_CONTRACT_STATUS_LIST) edit_by = models.ForeignKey(Profile) Although this problem can be solve with just renaming some of the fields. I wonder if when doing some django orm operation could produce a problem. thanks james --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---