Skip to content

Commit 161f046

Browse files
author
Emmanouil Konstantinidis
committed
Init Required Fields
1 parent 988c568 commit 161f046

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ 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+
# for name, field in serializer().get_fields().items():
37+
# print(name)
38+
# print(dir(field))
39+
# print('--------')
3140

3241
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)