mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 01:47:59 +03:00 
			
		
		
		
	Merge pull request #2371 from robbyt/patch-4
fix the serializer widget style formatting documentation
This commit is contained in:
		
						commit
						f8e310fdbb
					
				| 
						 | 
					@ -124,7 +124,7 @@ The first part of the serializer class defines the fields that get serialized/de
 | 
				
			||||||
 | 
					
 | 
				
			||||||
A serializer class is very similar to a Django `Form` class, and includes similar validation flags on the various fields, such as `required`, `max_length` and `default`.
 | 
					A serializer class is very similar to a Django `Form` class, and includes similar validation flags on the various fields, such as `required`, `max_length` and `default`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The field flags can also control how the serializer should be displayed in certain circumstances, such as when rendering to HTML. The `style={'type': 'textarea'}` flag above is equivelent to using `widget=widgets.Textarea` on a Django `Form` class. This is particularly useful for controlling how the browsable API should be displayed, as we'll see later in the tutorial.
 | 
					The field flags can also control how the serializer should be displayed in certain circumstances, such as when rendering to HTML. The `{'base_template': 'textarea.html'}` flag above is equivelent to using `widget=widgets.Textarea` on a Django `Form` class. This is particularly useful for controlling how the browsable API should be displayed, as we'll see later in the tutorial.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
We can actually also save ourselves some time by using the `ModelSerializer` class, as we'll see later, but for now we'll keep our serializer definition explicit.
 | 
					We can actually also save ourselves some time by using the `ModelSerializer` class, as we'll see later, but for now we'll keep our serializer definition explicit.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -206,7 +206,7 @@ One nice property that serializers have is that you can inspect all the fields i
 | 
				
			||||||
    SnippetSerializer():
 | 
					    SnippetSerializer():
 | 
				
			||||||
        id = IntegerField(label='ID', read_only=True)
 | 
					        id = IntegerField(label='ID', read_only=True)
 | 
				
			||||||
        title = CharField(allow_blank=True, max_length=100, required=False)
 | 
					        title = CharField(allow_blank=True, max_length=100, required=False)
 | 
				
			||||||
        code = CharField(style={'type': 'textarea'})
 | 
					        code = CharField(style={'base_template': 'textarea.html'})
 | 
				
			||||||
        linenos = BooleanField(required=False)
 | 
					        linenos = BooleanField(required=False)
 | 
				
			||||||
        language = ChoiceField(choices=[('Clipper', 'FoxPro'), ('Cucumber', 'Gherkin'), ('RobotFramework', 'RobotFramework'), ('abap', 'ABAP'), ('ada', 'Ada')...
 | 
					        language = ChoiceField(choices=[('Clipper', 'FoxPro'), ('Cucumber', 'Gherkin'), ('RobotFramework', 'RobotFramework'), ('abap', 'ABAP'), ('ada', 'Ada')...
 | 
				
			||||||
        style = ChoiceField(choices=[('autumn', 'autumn'), ('borland', 'borland'), ('bw', 'bw'), ('colorful', 'colorful')...
 | 
					        style = ChoiceField(choices=[('autumn', 'autumn'), ('borland', 'borland'), ('bw', 'bw'), ('colorful', 'colorful')...
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user