Re: anyone solve this problem

2021-01-08 Thread Praveen chaduvala
Thank you for your response.
I got the answer in someone's tutorial.

On Fri, Jan 8, 2021, 6:26 PM Xavier Ordoquy  wrote:

> Hi,
>
> The Django REST Framework tutorial, step6 should show you how to do that.
> The SnippetViewSet uses the SnippetSerializer to set the current user as
> the owner of the snippet created.
>
> Regards,
> Linovia,
> Xavier O.
>
> Le 8 janv. 2021 à 12:43, Praveen chaduvala  a écrit
> :
>
> django - how to add current active user as foreign key to the create post
> model in djangorestframework? - Stack Overflow
> 
>
>
> --
> 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/3c63250a-22f3-43f7-bcfd-833e422be73an%40googlegroups.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-framework+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-rest-framework/348387A6-FDB6-4FCC-B73B-3560DB524E0D%40linovia.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-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CAH5_3zkFW7uWgyfNKSk_1Lz8CrHDpN8meVOmMEOpyZv_umEs6w%40mail.gmail.com.


Why make a query before create when unique=True?

2021-01-08 Thread Barış Sermet
Hi there!

I have User model and serializer class which represents it.

*class User(models.Model):*
*username = models.CharField(unique=True, max_length=50)*
*is_admin = models.BooleanField(default=False)*

*class CreateUserSerializer(serializers.ModelSerializer):*
* class Meta:*
*model = User*
*fields = ("username", "is_admin")*

*def create(self, validated_data: Dict[str, Any]) -> User:*
*username = validated_data["username"]*

*try:*
*user_object = User.objects.create(username=username)*
*except IntegrityError:*
*raise UserAlreadyRegistered()*

*return user_object*

My database holds lots of users(appr. 10 million). When I create another 
user, Django Rest Framework look at the model fields and check that if 
there are any unique=True fields.
If there are, then it assigns "UniqueValidator". This validator calls 
"filter_queryset" which means it query the database and check that 
are there any given username record. If there are not, then it creates the 
user.

My question is, why DRF make a query before create operation? Since 
database(PostgreSQL) holds the field attributes, it knows that 
username field is unique, and it can throw an exception if I try to create 
user with the same username field. The reason I'm asking it, my application 
gets a lot of create operation, and each create operation I have to query 
my database, which is I think more costly than create it wihout making a 
filter query. 
Do I missing something in this operation?

Thanks!

-- 
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/7d2b7aa3-2be3-4b21-9032-c1438e22754an%40googlegroups.com.


Re: anyone solve this problem

2021-01-08 Thread Xavier Ordoquy
Hi,

The Django REST Framework tutorial, step6 should show you how to do that.
The SnippetViewSet uses the SnippetSerializer to set the current user as the 
owner of the snippet created.

Regards,
Linovia,
Xavier O.

> Le 8 janv. 2021 à 12:43, Praveen chaduvala  a écrit :
> 
> django - how to add current active user as foreign key to the create post 
> model in djangorestframework? - Stack Overflow 
> 
>   
> 
> -- 
> 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/3c63250a-22f3-43f7-bcfd-833e422be73an%40googlegroups.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-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/348387A6-FDB6-4FCC-B73B-3560DB524E0D%40linovia.com.


anyone solve this problem

2021-01-08 Thread Praveen chaduvala
django - how to add current active user as foreign key to the create post 
model in djangorestframework? - Stack Overflow 

  

-- 
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/3c63250a-22f3-43f7-bcfd-833e422be73an%40googlegroups.com.


Migration to LDAP authentication

2021-01-08 Thread Shaharyar Shamshi
Hello everyone first of all thank you for looking into the message actually 
As of now we are using token authentication in DRF one of our client has 
asked for the LDAP authentication can anyone help me understanding which 
will be better approach and also how can I migrate to LDAP from token 
authentication

-- 
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/fdd83d36-6780-4f5c-96db-e25669ec0a4dn%40googlegroups.com.