edigiacomo/django-statusboard

Allow create uncategorized services from web interface and REST API

edigiacomo opened this issue · 0 comments

From Python code, I can create an uncategorized service (i.e. service that doesn't belong to any service group).

s = Service(name="ciccioriccio", status=0)
s.full_clean() 
s.save()

These services are listed in an "uncategorized" section of the home page.

image

However, from web interface and REST API, I cannot create an uncategorized service (the asterisk after "Gruppi" means that it's mandatory to choose at least one group).

image

$ curl -X POST -u admin:admin -H "Content-Type: application/json" -d '{"name":"ciccioriccio", "status": 0}' localhost:8000/status/api/v0.1/service/
 {"groups":["Campo obbligatorio."]}

The solution is in the documentation. From https://docs.djangoproject.com/en/2.2/topics/forms/modelforms/#modelform:

If the model field has blank=True, then required is set to False on the form field. Otherwise, required=True.