Coverage for apis_core/utils/fields.py: 0%

6 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-22 07:51 +0000

1from django.db import models 

2 

3from apis_core.generic.forms.widgets import NewlineSeparatedListWidget 

4 

5 

6class NewlineSeparatedListField(models.TextField): 

7 """ 

8 This field is basically a textfield with a custom widget. 

9 It uses the NewlineSeparatedListWidget to provide a simply way 

10 for users to enter multiple values without having to think about 

11 the separator. 

12 """ 

13 

14 def formfield(self, form_class=None, choices_form_class=None, **kwargs): 

15 kwargs["widget"] = NewlineSeparatedListWidget(attrs={"class": "mb-1"}) 

16 return super().formfield( 

17 form_class=form_class, choices_form_class=choices_form_class, **kwargs 

18 )