Guys just found a solution.
Thanks to those that did contribute, I did appreciate it.

On Fri, Mar 31, 2023 at 1:24 PM Amed Sheriff <amedsher...@gmail.com> wrote:

> Hello Tanveer Ahmad,
>
> We are not sending the ID rather the FK value associated with which userid
> (a name which already unique)
>
> Thanks by the way.
>
> On Thu, Mar 30, 2023 at 12:16 AM Tanveer Ahmad <ta551...@gmail.com> wrote:
>
>> I think so, there's no way you have to send id only that must be unique
>>
>> On Thu, Mar 30, 2023, 4:06 AM Amed Sheriff <amedsher...@gmail.com> wrote:
>>
>>> Hello Team,
>>>
>>> Please i need help with this which has taken me over two weeks and still
>>> couldn't come up with anything after surfing the internet.
>>>
>>> Is there any posibility to post data to foreign key using the value
>>> rather than the FK ID. Bcz i have tried all kinds of scenarios but none
>>> seemed to work with this even though they do refer to  "SlugRelatedField"
>>> usage.
>>>
>>> This is my model.
>>>
>>> class Counter(models.Model):
>>>     userid = models.ForeignKey(Identification,related_name="userName",
>>>      verbose_name=_("User ID"), on_delete=models.CASCADE, null=True)
>>>     counter = models.IntegerField(_("Counter"), blank=True, null=True)
>>>     date_and_time = models.DateTimeField(_("Date and Time"),
>>> default=timezone.now)
>>>
>>>     def __str__(self):
>>>         return str(self.counter)
>>>
>>> This is my serializer.
>>>
>>> class Message_Counter_Serializer(serializers.ModelSerializer):
>>>     userid = serializers.SlugRelatedField(
>>>         slug_field='userName',
>>>         queryset=Identification.objects.all()
>>>     )
>>>
>>>     class Meta:
>>>         model = Counter
>>>         fields = '__all__'
>>>
>>> Post:
>>> {
>>> "counter": "2",
>>> "userid": "ya"
>>> }
>>>
>>> Error:
>>>  {"userid":["Invalid value."]}
>>>
>>> Thanks in advance
>>>
>>> Best regards
>>>
>>> Amed.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django REST framework" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-rest-framework+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-rest-framework/CADteO3_BuN97kaGyiHU-b5VETJHLyxB4tD-ePn_FTuKEZsyKQg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-rest-framework/CADteO3_BuN97kaGyiHU-b5VETJHLyxB4tD-ePn_FTuKEZsyKQg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django REST framework" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-rest-framework+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-rest-framework/CADz4rYbtxy7ZWuCRKf%2BvkFwoVsDwVHy%2BB%3DVzfr7H5t2Z_WdLEg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-rest-framework/CADz4rYbtxy7ZWuCRKf%2BvkFwoVsDwVHy%2BB%3DVzfr7H5t2Z_WdLEg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CADteO3_nhWdHzmXU3Sed4jL4gzG9yM4L_18ZU829_p7jaB5-ng%40mail.gmail.com.

Reply via email to