If you're serializing as JSON, that primary key is literally just integer then, and the foreign key relationship requires an instance of that foreign key. So you'll need to fetch an instance of the object first.
I've had this issue before, that's how I resolved it. On Friday, April 17, 2020 at 1:51:05 PM UTC+8, shreehari Vaasistha L wrote: > > i get this error when trying in your way: > > Cannot assign "2": "User.highest_degree" must be a "Degree" instance. > > On Thursday, April 16, 2020 at 5:31:07 PM UTC+5:30, Gavin Wiener wrote: >> >> Couldn't the User just have a ForeignKey on countries? >> >> On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L >> wrote: >>> >>> how can i use model x values as choices for model y ? >>> >>> for eg: >>> class countries(models.Model): >>> country = models.CharField(max_length=200) >>> >>> def __str__(self): >>> return self.country >>> >>> class User(AbstractUser): >>> """User model.""" >>> >>> username = None >>> full_name = models.CharField(_("Full Name"), max_length=50, default="Full >>> Name") >>> country_choices = models.CharField(choices=countries >>> >> -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c563335e-cd3f-4204-9aec-6c098dc3a525%40googlegroups.com.