mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 18:08:03 +03:00 
			
		
		
		
	Update documentation
This commit is contained in:
		
							parent
							
								
									6cce0681a9
								
							
						
					
					
						commit
						78f5bcb5cb
					
				| 
						 | 
					@ -807,9 +807,9 @@ serializer.errors
 | 
				
			||||||
        # would need to be handled.
 | 
					        # would need to be handled.
 | 
				
			||||||
        profile = instance.profile
 | 
					        profile = instance.profile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        user.username = validated_data.get('username', instance.username)
 | 
					        instance.username = validated_data.get('username', instance.username)
 | 
				
			||||||
        user.email = validated_data.get('email', instance.email)
 | 
					        instance.email = validated_data.get('email', instance.email)
 | 
				
			||||||
        user.save()
 | 
					        instance.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        profile.is_premium_member = profile_data.get(
 | 
					        profile.is_premium_member = profile_data.get(
 | 
				
			||||||
            'is_premium_member',
 | 
					            'is_premium_member',
 | 
				
			||||||
| 
						 | 
					@ -821,7 +821,7 @@ serializer.errors
 | 
				
			||||||
         )
 | 
					         )
 | 
				
			||||||
        profile.save()
 | 
					        profile.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return user
 | 
					        return instance
 | 
				
			||||||
</code></pre>
 | 
					</code></pre>
 | 
				
			||||||
<p>Because the behavior of nested creates and updates can be ambiguous, and may require complex dependancies between related models, REST framework 3 requires you to always write these methods explicitly. The default <code>ModelSerializer</code> <code>.create()</code> and <code>.update()</code> methods do not include support for writable nested representations.</p>
 | 
					<p>Because the behavior of nested creates and updates can be ambiguous, and may require complex dependancies between related models, REST framework 3 requires you to always write these methods explicitly. The default <code>ModelSerializer</code> <code>.create()</code> and <code>.update()</code> methods do not include support for writable nested representations.</p>
 | 
				
			||||||
<p>It is possible that a third party package, providing automatic support some kinds of automatic writable nested representations may be released alongside the 3.1 release.</p>
 | 
					<p>It is possible that a third party package, providing automatic support some kinds of automatic writable nested representations may be released alongside the 3.1 release.</p>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -411,8 +411,7 @@
 | 
				
			||||||
<hr />
 | 
					<hr />
 | 
				
			||||||
<h2 id="setting-up-a-new-environment">Setting up a new environment</h2>
 | 
					<h2 id="setting-up-a-new-environment">Setting up a new environment</h2>
 | 
				
			||||||
<p>Before we do anything else we'll create a new virtual environment, using <a href="http://www.virtualenv.org/en/latest/index.html">virtualenv</a>.  This will make sure our package configuration is kept nicely isolated from any other projects we're working on.</p>
 | 
					<p>Before we do anything else we'll create a new virtual environment, using <a href="http://www.virtualenv.org/en/latest/index.html">virtualenv</a>.  This will make sure our package configuration is kept nicely isolated from any other projects we're working on.</p>
 | 
				
			||||||
<pre><code>:::bash
 | 
					<pre><code>virtualenv env
 | 
				
			||||||
virtualenv env
 | 
					 | 
				
			||||||
source env/bin/activate
 | 
					source env/bin/activate
 | 
				
			||||||
</code></pre>
 | 
					</code></pre>
 | 
				
			||||||
<p>Now that we're inside a virtualenv environment, we can install our package requirements.</p>
 | 
					<p>Now that we're inside a virtualenv environment, we can install our package requirements.</p>
 | 
				
			||||||
| 
						 | 
					@ -460,12 +459,8 @@ class Snippet(models.Model):
 | 
				
			||||||
    title = models.CharField(max_length=100, blank=True, default='')
 | 
					    title = models.CharField(max_length=100, blank=True, default='')
 | 
				
			||||||
    code = models.TextField()
 | 
					    code = models.TextField()
 | 
				
			||||||
    linenos = models.BooleanField(default=False)
 | 
					    linenos = models.BooleanField(default=False)
 | 
				
			||||||
    language = models.CharField(choices=LANGUAGE_CHOICES,
 | 
					    language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
 | 
				
			||||||
                                default='python',
 | 
					    style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)
 | 
				
			||||||
                                max_length=100)
 | 
					 | 
				
			||||||
    style = models.CharField(choices=STYLE_CHOICES,
 | 
					 | 
				
			||||||
                             default='friendly',
 | 
					 | 
				
			||||||
                             max_length=100)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class Meta:
 | 
					    class Meta:
 | 
				
			||||||
        ordering = ('created',)
 | 
					        ordering = ('created',)
 | 
				
			||||||
| 
						 | 
					@ -483,14 +478,11 @@ from snippets.models import Snippet, LANGUAGE_CHOICES, STYLE_CHOICES
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SnippetSerializer(serializers.Serializer):
 | 
					class SnippetSerializer(serializers.Serializer):
 | 
				
			||||||
    pk = serializers.IntegerField(read_only=True)
 | 
					    pk = serializers.IntegerField(read_only=True)
 | 
				
			||||||
    title = serializers.CharField(required=False, allow_blank=True
 | 
					    title = serializers.CharField(required=False, allow_blank=True, max_length=100)
 | 
				
			||||||
                                  max_length=100)
 | 
					 | 
				
			||||||
    code = serializers.CharField(style={'type': 'textarea'})
 | 
					    code = serializers.CharField(style={'type': 'textarea'})
 | 
				
			||||||
    linenos = serializers.BooleanField(required=False)
 | 
					    linenos = serializers.BooleanField(required=False)
 | 
				
			||||||
    language = serializers.ChoiceField(choices=LANGUAGE_CHOICES,
 | 
					    language = serializers.ChoiceField(choices=LANGUAGE_CHOICES, default='python')
 | 
				
			||||||
                                       default='python')
 | 
					    style = serializers.ChoiceField(choices=STYLE_CHOICES, default='friendly')
 | 
				
			||||||
    style = serializers.ChoiceField(choices=STYLE_CHOICES,
 | 
					 | 
				
			||||||
                                    default='friendly')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create(self, validated_data):
 | 
					    def create(self, validated_data):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
| 
						 | 
					@ -552,6 +544,8 @@ data = JSONParser().parse(stream)
 | 
				
			||||||
<pre><code>serializer = SnippetSerializer(data=data)
 | 
					<pre><code>serializer = SnippetSerializer(data=data)
 | 
				
			||||||
serializer.is_valid()
 | 
					serializer.is_valid()
 | 
				
			||||||
# True
 | 
					# True
 | 
				
			||||||
 | 
					serializer.validated_data
 | 
				
			||||||
 | 
					# OrderedDict([('title', ''), ('code', 'print "hello, world"\n'), ('linenos', False), ('language', 'python'), ('style', 'friendly')])
 | 
				
			||||||
serializer.save()
 | 
					serializer.save()
 | 
				
			||||||
# <Snippet: Snippet object>
 | 
					# <Snippet: Snippet object>
 | 
				
			||||||
</code></pre>
 | 
					</code></pre>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user