|
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,16 @@ 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.objects.filter( |
| 150 | + Q(project=project) | Q(project=None) |
| 151 | + ), |
| 152 | + required=False, |
| 153 | + ) |
147 | 154 |
|
148 | 155 | class Meta: |
149 | 156 | model = Patch |
150 | | - fields = ['state', 'archived', 'delegate'] |
| 157 | + fields = ['state', 'archived', 'delegate', 'labels'] |
151 | 158 | widgets = { |
152 | 159 | 'state': forms.Select(attrs={'class': 'change-property-state'}), |
153 | 160 | 'archived': forms.CheckboxInput( |
@@ -223,6 +230,12 @@ def __init__(self, project, *args, **kwargs): |
223 | 230 | label='Delegate to', |
224 | 231 | required=False, |
225 | 232 | ) |
| 233 | + self.fields['labels'] = forms.ModelMultipleChoiceField( |
| 234 | + queryset=Label.objects.filter( |
| 235 | + Q(project=project) | Q(project=None) |
| 236 | + ), |
| 237 | + required=False, |
| 238 | + ) |
226 | 239 | self.fields['state'] = OptionalModelChoiceField( |
227 | 240 | queryset=State.objects.all(), |
228 | 241 | placeholder='Change state', |
@@ -254,6 +267,13 @@ def save(self, instance, commit=True): |
254 | 267 |
|
255 | 268 | if commit: |
256 | 269 | instance.save() |
| 270 | + |
| 271 | + for f in opts.many_to_many: |
| 272 | + if f.name not in data: |
| 273 | + continue |
| 274 | + |
| 275 | + getattr(instance, f.name).add(*data[f.name]) |
| 276 | + |
257 | 277 | return instance |
258 | 278 |
|
259 | 279 |
|
|
0 commit comments