Skip to content

Commit 333fbf6

Browse files
Merge pull request #11 from ekonstantinidis/required-fields
Required Fields
2 parents 988c568 + 21477f3 commit 333fbf6

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
Document Web APIs made with Django Rest Framework.
44

55

6-
### Prerequisites
6+
### Supports
77

8-
- Python (3.3, 3.4, 3.5)
9-
- Django (1.8, 1.9)
8+
- Python (2.7, 3.3, 3.4, 3.5)
9+
- Django (1.7, 1.8, 1.9)
1010
- Django Rest Framework (3+)
1111

1212

13-
### Development
13+
### Development & Demo Project
14+
If you are looking to develop this package with one of your own django projects:
1415

1516
pyvenv env
1617
env/bin/pip install -r requirements.txt
17-
18-
# To test within another django project
1918
pip install -e ~/Projects/drf-docs/
2019

20+
If you want to use the demo app to work on this package:
21+
Included in this repo you can find the demo project(at `/demo`). It is a project with *Django* & *Django Rest Framework* that will allow you to work with this project. For more information on how you can set it up please check the [README.md](demo/README.md) of the demo project.
22+
2123
### Installation
2224

2325
Install using pip:
@@ -38,17 +40,17 @@ Finally include the `rest_framework_docs` urls in your `urls.py`:
3840
url(r'^docs/', include('rest_framework_docs.urls')),
3941
]
4042

41-
### Development & Demo Project
42-
Included in this repo you can find the demo project(at `/demo`). It is a project with *Django* & *Django Rest Framework* that will allow you to work with this project. For more information on how you can set it up please readme the [README.md](demo/README.md) of the demo project.
4343

4444
### Settings
4545

4646
REST_FRAMEWORK_DOCS = {
4747
'HIDDEN': True # Default: False
4848
}
4949

50+
5051
### Roadmap
5152

53+
- [ ] Creade demo app
5254
- [ ] Support Python 2 & Python 3
5355
- [ ] Support DRF 3+
5456
- [ ] Open Pull Request to include in DRF

demo/project/organisations/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Organisation(models.Model):
1010
modified = models.DateTimeField(auto_now=True)
1111

1212
name = models.CharField(unique=True, max_length=100)
13-
slug = models.SlugField(unique=True)
13+
slug = models.SlugField(unique=True, null=True, blank=True)
1414
members = models.ManyToManyField(User, through='Membership', through_fields=('organisation', 'user'))
1515

1616
is_active = models.BooleanField(default=False)

rest_framework_docs/api_endpoint.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ def __get_serializer_fields__(self):
2727
if hasattr(self.callback.cls, 'serializer_class') and hasattr(self.callback.cls.serializer_class, 'get_fields'):
2828
serializer = self.callback.cls.serializer_class
2929
if hasattr(serializer, 'get_fields'):
30-
fields = [{"name": key, "type": str(value.__class__.__name__)} for key, value in serializer().get_fields().items()]
30+
fields = [{
31+
"name": key,
32+
"type": str(field.__class__.__name__),
33+
"required": field.required
34+
} for key, field in serializer().get_fields().items()]
35+
36+
# FIXME:
37+
# Show more attibutes of `field`?
3138

3239
return fields

rest_framework_docs/static/less/style.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ body {
3030
text-align: center;
3131
}
3232

33+
.label-required {
34+
padding: 2px 5px;
35+
margin-left: 5px;
36+
}
37+
3338
/* @end Misc */
3439

3540

rest_framework_docs/templates/rest_framework_docs/home.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Jump To <span class="caret"></span></a>
77
<ul class="dropdown-menu">
88
{% for group in endpoints_grouped %}
9-
<li><a href="#{{ group.grouper|lower }}">{{ group.grouper }}</a></li>
9+
<li><a href="#{{ group.grouper|lower }}-nav">{{ group.grouper }}</a></li>
1010
{% endfor %}
1111
</ul>
1212
</li>
@@ -20,7 +20,7 @@
2020
{% if endpoints_grouped %}
2121
{% for group in endpoints_grouped %}
2222

23-
<h1 id="{{ group.grouper|lower }}">{{group.grouper}}</h1>
23+
<h1 id="{{ group.grouper|lower }}-nav">{{group.grouper}}</h1>
2424

2525
<div class="panel-group" role="tablist">
2626

@@ -52,7 +52,7 @@ <h4 class="panel-title title">
5252
<p>Fields:</p>
5353
<ul class="list fields">
5454
{% for field in endpoint.fields %}
55-
<li class="field">{{ field.name }}: {{ field.type }}</li>
55+
<li class="field">{{ field.name }}: {{ field.type }} {% if field.required %}<span class="label label-primary label-required" title="Required">R</span>{% endif %}</li>
5656
{% endfor %}
5757
</ul>
5858
{% else %}

0 commit comments

Comments
 (0)