aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--servo/forms/devices.py15
-rw-r--r--servo/models/device.py9
-rw-r--r--servo/views/device.py2
3 files changed, 15 insertions, 11 deletions
diff --git a/servo/forms/devices.py b/servo/forms/devices.py
index 8d41c02..a95715e 100644
--- a/servo/forms/devices.py
+++ b/servo/forms/devices.py
@@ -33,8 +33,7 @@ class DeviceSearchForm(forms.Form):
def __init__(self, *args, **kwargs):
super(DeviceSearchForm, self).__init__(*args, **kwargs)
- self.fields['description'] = AutocompleteCharField(
- '/api/device_models/',
+ self.fields['description'] = AutocompleteCharField('/api/device_models/',
max_length=128,
required=False,
label=_('Description contains')
@@ -42,17 +41,19 @@ class DeviceSearchForm(forms.Form):
class DeviceForm(forms.ModelForm):
+ """The form for editing devices in the /devices view"""
+ """
+ tags = forms.ModelMultipleChoiceField(
+ queryset=Tag.objects.filter(type='device'),
+ required=False
+ )
+ """
class Meta:
model = Device
exclude = ('spec', 'customers', 'files', 'image_url',
'exploded_view_url', 'manual_url', )
widgets = {'purchased_on': DatepickerInput()}
- tags = forms.ModelMultipleChoiceField(
- queryset=Tag.objects.filter(type='device'),
- required=False
- )
-
class DeviceUploadForm(forms.Form):
datafile = forms.FileField(
diff --git a/servo/models/device.py b/servo/models/device.py
index 4688423..d994d20 100644
--- a/servo/models/device.py
+++ b/servo/models/device.py
@@ -157,8 +157,9 @@ class Device(models.Model):
parts_and_labor_covered = models.BooleanField(default=False, editable=False)
+ tags = GenericRelation(TaggedItem, null=True, blank=True)
notes = models.TextField(blank=True, default="", verbose_name=_("notes"))
- tags = GenericRelation(TaggedItem)
+
photo = models.ImageField(
null=True,
blank=True,
@@ -208,19 +209,21 @@ class Device(models.Model):
def tag_choices(self):
return TaggedItem.objects.filter(content_type__model="device").distinct("tag")
- def add_tags(self, tags):
+ def add_tags(self, tags: list):
tags = [x for x in tags if x != ''] # Filter out empty tags
if not tags:
return
content_type = ContentType.objects.get_for_model(Device)
-
+
for t in tags:
tag, created = TaggedItem.objects.get_or_create(content_type=content_type,
object_id=self.pk,
tag=t)
+
tag.save()
+
def get_icon(self):
if re.match('iPad', self.description):
diff --git a/servo/views/device.py b/servo/views/device.py
index 0eda090..6436730 100644
--- a/servo/views/device.py
+++ b/servo/views/device.py
@@ -146,8 +146,8 @@ def edit_device(request, pk=None, product_line=None, model=None):
if form.is_valid():
device = form.save()
- messages.success(request, _(u"%s saved") % device.description)
device.add_tags(request.POST.getlist('tag'))
+ messages.success(request, _(u"%s saved") % device.description)
return redirect(view_device,
pk=device.pk,