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
with a Foreign Key field, one-to-many relationship:
https://docs.djangoproject.com/en/3.0/topics/db/examples/many_to_one/
Antje
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/683251c6-27ab-4454-90d6-532fdcc749ce%40googlegroups.com.
Object of type ValueError is not JSON serializable
class UserCreateApiView(CreateAPIView): serializer_class = UserCreateSerializer def post(self,request): try: serializer=UserCreateSerializer(data=request.data) if serializer.is_valid(): new_user = User()
new_user.highest_degree=serializer.data['highest_degree'] #new_user.state_registered=serializer.data['state_registered'] new_user.country_choices=serializer.data['country_choices']
new_user.save() print(new_user.doc_id) return Response(status=status.HTTP_200_OK) return Response(status=status.HTTP_406_NOT_ACCEPTABLE) except Exception as e: return Response(e)
with a Foreign Key field, one-to-many relationship:
https://docs.djangoproject.com/en/3.0/topics/db/examples/many_to_one/
Antje
On 4/16/20 6:52 AM, 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...@googlegroups.com.
--
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...@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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALVb5jEr-MnU7Z_6x%2BD30RrHGT4zBVSCsRGK4eGpikLXR%2BRQow%40mail.gmail.com.