mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 09:57:55 +03:00 
			
		
		
		
	Docs: DjangoModelPermissions works on views with get_queryset() method. (#7693)
Sentinel querysets not needed after v3.1.2
This commit is contained in:
		
							parent
							
								
									234527959d
								
							
						
					
					
						commit
						e32ebc4199
					
				| 
						 | 
					@ -169,7 +169,7 @@ This permission is suitable if you want to your API to allow read permissions to
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## DjangoModelPermissions
 | 
					## DjangoModelPermissions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
This permission class ties into Django's standard `django.contrib.auth` [model permissions][contribauth].  This permission must only be applied to views that have a `.queryset` property set. Authorization will only be granted if the user *is authenticated* and has the *relevant model permissions* assigned.
 | 
					This permission class ties into Django's standard `django.contrib.auth` [model permissions][contribauth].  This permission must only be applied to views that have a `.queryset` property or `get_queryset()` method. Authorization will only be granted if the user *is authenticated* and has the *relevant model permissions* assigned.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* `POST` requests require the user to have the `add` permission on the model.
 | 
					* `POST` requests require the user to have the `add` permission on the model.
 | 
				
			||||||
* `PUT` and `PATCH` requests require the user to have the `change` permission on the model.
 | 
					* `PUT` and `PATCH` requests require the user to have the `change` permission on the model.
 | 
				
			||||||
| 
						 | 
					@ -179,12 +179,6 @@ The default behaviour can also be overridden to support custom model permissions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To use custom model permissions, override `DjangoModelPermissions` and set the `.perms_map` property.  Refer to the source code for details.
 | 
					To use custom model permissions, override `DjangoModelPermissions` and set the `.perms_map` property.  Refer to the source code for details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Using with views that do not include a `queryset` attribute.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
If you're using this permission with a view that uses an overridden `get_queryset()` method there may not be a `queryset` attribute on the view. In this case we suggest also marking the view with a sentinel queryset, so that this class can determine the required permissions. For example:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    queryset = User.objects.none()  # Required for DjangoModelPermissions
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## DjangoModelPermissionsOrAnonReadOnly
 | 
					## DjangoModelPermissionsOrAnonReadOnly
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Similar to `DjangoModelPermissions`, but also allows unauthenticated users to have read-only access to the API.
 | 
					Similar to `DjangoModelPermissions`, but also allows unauthenticated users to have read-only access to the API.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user