Commit 15d584fd authored by Vasyl Bodnaruk's avatar Vasyl Bodnaruk

finished add functional for added tags to edit view if they exist.

Refactor code, add some logic ro template
parent 60e6b409
......@@ -62,7 +62,9 @@
<input
type="text"
id="radar"
{% if news.get_radar %}
data-initial-value='[{"text": "{{ news.get_radar }}", "value" : "{{ news.get_radar.id }}"}]'
{% endif %}
data-url="{% url 'auto' slug='radar' %}"
data-load-once="true"
class="multiselect singleInputDynamic"
......@@ -78,7 +80,9 @@
type="text"
id="industry"
class="multiselect"
{% if news.get_industry %}
data-initial-value='[{"text": "{{ news.get_industry }}", "value" : "{{ news.get_industry.id }}"}]'
{% endif %}
data-url="{% url 'auto' slug='industry' %}"
data-load-once="true"
name="industry"/>
......@@ -93,7 +97,9 @@
type="text"
id="function"
class="multiselect"
{% if news.get_function %}
data-initial-value='[{"text": "{{ news.get_function }}", "value" : "{{ news.get_function.id }}"}]'
{% endif %}
data-url="{% url 'auto' slug='function' %}"
data-load-once="true"
name="function"/>
......@@ -110,7 +116,9 @@
type="text"
id="media"
class="multiselect"
{% if news.get_media %}
data-initial-value='[{"text": "{{ news.get_media }}", "value" : "{{ news.get_media.id }}"}]'
{% endif %}
data-url="{% url 'auto' slug='media' %}"
data-load-once="true"
name="media"/>
......@@ -130,7 +138,9 @@
type="text"
id="technology"
class="multiselect"
{% if news.get_technology %}
data-initial-value='[{"text": "{{ news.get_technology }}", "value" : "{{ news.get_technology.id }}"}]'
{% endif %}
data-url="{% url 'auto' slug='technology' %}"
data-load-once="true"
name="technology"/>
......@@ -145,7 +155,9 @@
type="text"
id="type"
class="multiselect"
{% if news.get_type %}
data-initial-value='[{"text": "{{ news.get_type }}", "value" : "{{ news.get_type.id }}"}]'
{% endif %}
data-url="{% url 'auto' slug='type' %}"
data-load-once="true"
name="type"/>
......@@ -160,7 +172,9 @@
type="text"
id="region"
class="multiselect"
{% if news.get_region %}
data-initial-value='[{"text": "{{ news.get_region }}", "value" : "{{ news.get_region.id }}"}]'
{% endif %}
data-url="{% url 'auto' slug='region' %}"
data-load-once="true"
name="region"/>
......@@ -177,7 +191,6 @@
</div>
<!-- Tag -->
{{ news.get_tags }}
<div class="form-group row">
<label for="tag" class="offset-1 col-2 col-form-label">Tag</label>
<div class="col-6">
......@@ -186,7 +199,9 @@
multiple
id="tag"
class="multiselect"
data-initial-value='[{"text": "Algeria", "value" : "Algeria"}, {"text": "Angola", "value" : "Angola"}]'
{% if news.get_tags_json %}
data-initial-value='{{ news.get_tags_json }}'
{% endif %}
data-url="{% url 'auto' slug='tags' %}"
data-load-once="true"
name="tags"/>
......
......@@ -33,10 +33,14 @@ class News(models.Model):
def get_tags(self):
if self.tags_id:
# tags = json.loads(self.tags_id, encoding='utf-8')
return self.tags_id
# return self.tags_id.split(',')
# return WpEsiTechnology.objects.filter(id__in=tags)
tags = json.loads(self.tags_id)
return WpEsiTechnology.objects.filter(id__in=tags)
return None
def get_tags_json(self):
tags = self.get_tags()
if tags:
return json.dumps([{'text': i.name, 'value': i.id} for i in tags])
return None
def get_technology(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment