Tuesday, February 26, 2019

Re: Invalid pk \"1\" - object does not exist.

Please ; can i any one explane for me what is django and what is the relation between it any the database ? please :(

Le mar. 26 févr. 2019 à 11:02, <anthony.tedde.85@gmail.com> a écrit :
Hello,

What if you use kind of the following as json data:
nb: The following model is a simplified version with only two fields (name and manager which is a FK to itself such as in yours).

[
  {
    "model": "YourApp.YourModelName",
    "pk": 1,
    "fields": {
      "name": "toto",
      "manager": null
    }
  },
  {
    "model": "YourApp.YourModelName",
    "pk": 2,
    "fields": {
      "name": "tata",
      "manager": 1
    }
  }
]

In that case you ensure that a manager object with pk equals to 1 already exists and therefore can be referred to .

'Hope it helps.

Le lundi 25 février 2019 14:36:05 UTC+1, optvi...@gmail.com a écrit :
getting error


{"manager":["Invalid pk \"1\" - object does not exist."]}


here is my model class

class Employee(models.Model):

MANAGER = 'MGR'
STANDARD = 'STD'


EMPLOYEE_TYPES = (

(MANAGER, 'manager'),
(STANDARD, 'employee')

)


role = models.CharField(max_length=25, choices=EMPLOYEE_TYPES)
name = models.CharField(max_length=100, null=True, blank=True)
employee_id = models.CharField(max_length=100, null=True, blank=True)
manager = models.ForeignKey('self', null=True, related_name='employee',on_delete=models.CASCADE)


and json data which i am using to save in table

{
"role":"MGR",
"name":"John",
"employee_id" :"IN",
"manager":1

}




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bcac16dc-e8d3-4044-ab69-eac06cbdc586%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANMmGeX_UL%3DvQAUd9szpxpayABygc4BqQkDYd19kdmhe70avXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment