--
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-fram...@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.
--
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-fram...@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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CAOaWsMGdZeV5qHzNhZuJLnMASBwq8dgg-CfqHi4yYj84Qr3UTg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CAOaWsMGdZeV5qHzNhZuJLnMASBwq8dgg-CfqHi4yYj84Qr3UTg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CADteO3_OuOeFn%3DGwXLaOssQ9HZnbra5ht_knBKpuJUon4ySzSQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CAHQdaQAva9%3D9CYgAb8KqBpnQvM4A68yV%3DROik0FQcD7RysZjwg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CAOaWsMHR9fFcdcm74--2MXvBs0vvCPK_45g5m76CW4Vny2FkUQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CADteO3-tBVgmdhLg09BYgWp5-reXAxLDW2jmnx6hkptY8HPkig%40mail.gmail.com.
Hello Team,Please could look into it for me maybe i am doing something wrong.
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__'
This is my View
class Counter_Viewsets(errorhandler, viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated, TokenHasResourceScope]
serializer_class = Message_Counter_Serializer
def get_queryset(self):
return Counter.objects.all().filter(userid__user_name=self.request.user)
This is my Post:
{
"counter": "2",
"userid": "yasmin"
}Thanks in advance.
On Thu, Mar 30, 2023 at 5:02 AM Umair Ramzan <umairper...@gmail.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CAHQdaQAva9%3D9CYgAb8KqBpnQvM4A68yV%3DROik0FQcD7RysZjwg%40mail.gmail.com.
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.
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.