|
14 | 14 |
|
15 | 15 | from patchwork.models import Bundle |
16 | 16 | from patchwork.models import Patch |
| 17 | +from patchwork.models import Label |
17 | 18 | from patchwork.models import State |
18 | 19 | from patchwork.models import UserProfile |
19 | 20 |
|
@@ -144,10 +145,14 @@ def __init__(self, instance=None, project=None, *args, **kwargs): |
144 | 145 | widget=forms.Select(attrs={'class': 'change-property-delegate'}), |
145 | 146 | required=False, |
146 | 147 | ) |
| 148 | + self.fields['labels'] = forms.ModelMultipleChoiceField( |
| 149 | + queryset=Label.get_project_labels(project), |
| 150 | + required=False, |
| 151 | + ) |
147 | 152 |
|
148 | 153 | class Meta: |
149 | 154 | model = Patch |
150 | | - fields = ['state', 'archived', 'delegate'] |
| 155 | + fields = ['state', 'archived', 'delegate', 'labels'] |
151 | 156 | widgets = { |
152 | 157 | 'state': forms.Select(attrs={'class': 'change-property-state'}), |
153 | 158 | 'archived': forms.CheckboxInput( |
@@ -223,6 +228,11 @@ def __init__(self, project, *args, **kwargs): |
223 | 228 | label='Delegate to', |
224 | 229 | required=False, |
225 | 230 | ) |
| 231 | + |
| 232 | + self.fields['labels'] = forms.ModelMultipleChoiceField( |
| 233 | + queryset=Label.get_project_labels(project), |
| 234 | + required=False, |
| 235 | + ) |
226 | 236 | self.fields['state'] = OptionalModelChoiceField( |
227 | 237 | queryset=State.objects.all(), |
228 | 238 | placeholder='Change state', |
@@ -254,6 +264,13 @@ def save(self, instance, commit=True): |
254 | 264 |
|
255 | 265 | if commit: |
256 | 266 | instance.save() |
| 267 | + |
| 268 | + for f in opts.many_to_many: |
| 269 | + if f.name not in data: |
| 270 | + continue |
| 271 | + |
| 272 | + getattr(instance, f.name).add(*data[f.name]) |
| 273 | + |
257 | 274 | return instance |
258 | 275 |
|
259 | 276 |
|
|
0 commit comments