Commit 154e9605 authored by Vasyl Bodnaruk's avatar Vasyl Bodnaruk

add multiple choice to edit view

parent 89a110c5
...@@ -81,8 +81,9 @@ ...@@ -81,8 +81,9 @@
type="text" type="text"
id="industry" id="industry"
class="multiselect" class="multiselect"
{% if news.get_industry %} multiple
data-initial-value='[{"text": "{{ news.get_industry }}", "value" : "{{ news.get_industry.id }}"}]' {% if news.get_industry_json %}
data-initial-value='{{ news.get_industry_json }}'
{% endif %} {% endif %}
data-url="{% url 'auto' slug='industry' %}" data-url="{% url 'auto' slug='industry' %}"
data-load-once="true" data-load-once="true"
...@@ -98,8 +99,9 @@ ...@@ -98,8 +99,9 @@
type="text" type="text"
id="function" id="function"
class="multiselect" class="multiselect"
{% if news.get_function %} multiple
data-initial-value='[{"text": "{{ news.get_function }}", "value" : "{{ news.get_function.id }}"}]' {% if news.get_function_json %}
data-initial-value='{{ news.get_function_json }}'
{% endif %} {% endif %}
data-url="{% url 'auto' slug='function' %}" data-url="{% url 'auto' slug='function' %}"
data-load-once="true" data-load-once="true"
...@@ -139,8 +141,9 @@ ...@@ -139,8 +141,9 @@
type="text" type="text"
id="technology" id="technology"
class="multiselect" class="multiselect"
{% if news.get_technology %} multiple
data-initial-value='[{"text": "{{ news.get_technology }}", "value" : "{{ news.get_technology.id }}"}]' {% if news.get_technology_json %}
data-initial-value='{{ news.get_technology_json }}'
{% endif %} {% endif %}
data-url="{% url 'auto' slug='technology' %}" data-url="{% url 'auto' slug='technology' %}"
data-load-once="true" data-load-once="true"
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
{% paginate news %} {% paginate news %}
{{ request.get_full_path }}
<form class="form"> <form class="form">
<table class="table table-hover"> <table class="table table-hover">
<thead class="thead-inverse"> <thead class="thead-inverse">
......
...@@ -10,6 +10,7 @@ class NewsForm(forms.Form): ...@@ -10,6 +10,7 @@ class NewsForm(forms.Form):
news = News.objects.get(pk=self.data['news_id']) news = News.objects.get(pk=self.data['news_id'])
news = self._make(news) news = self._make(news)
news.save() news.save()
print(news.technology_id)
def create(self): def create(self):
news = News() news = News()
...@@ -28,13 +29,15 @@ class NewsForm(forms.Form): ...@@ -28,13 +29,15 @@ class NewsForm(forms.Form):
if self.data['radar']: if self.data['radar']:
news.radar_id = self.data['radar'] news.radar_id = self.data['radar']
if self.data['industry']: if self.data['industry']:
news.industry_id = self.data['industry'] print('fdgdfgdfg', self.data['industry'])
news.industry_id = [int(i) for i in self.data['industry'].split(',')]
if self.data['function']: if self.data['function']:
news.function_id = self.data['function'] news.function_id = [int(i) for i in self.data['function'].split(',')]
if self.data['media']: if self.data['media']:
news.media_id = self.data['media'] news.media_id = self.data['media']
if self.data['technology']: if self.data['technology']:
news.technology_id = self.data['technology'] news.technology_id = [int(i) for i in self.data['technology'].split(',')]
print(news.technology_id)
if self.data['type']: if self.data['type']:
news.type_id = self.data['type'] news.type_id = self.data['type']
if self.data['region']: if self.data['region']:
...@@ -43,6 +46,7 @@ class NewsForm(forms.Form): ...@@ -43,6 +46,7 @@ class NewsForm(forms.Form):
news.publish_date = datetime.strptime(self.data['date'], '%Y-%m-%d') news.publish_date = datetime.strptime(self.data['date'], '%Y-%m-%d')
if self.data['tags']: if self.data['tags']:
print(self.data['tags'])
news.tags_id = [int(i) for i in self.data['tags'].split(',')] news.tags_id = [int(i) for i in self.data['tags'].split(',')]
return news return news
...@@ -21,9 +21,9 @@ class News(models.Model): ...@@ -21,9 +21,9 @@ class News(models.Model):
is_accepted = models.BooleanField(default=False) is_accepted = models.BooleanField(default=False)
radar_id = models.BigIntegerField(default=None, null=True, blank=True) radar_id = models.BigIntegerField(default=None, null=True, blank=True)
industry_id = models.BigIntegerField(default=None, null=True, blank=True) industry_id = models.CharField(max_length=255,default=None, null=True, blank=True)
function_id = models.BigIntegerField(default=None, null=True, blank=True) function_id = models.CharField(max_length=255,default=None, null=True, blank=True)
technology_id = models.BigIntegerField(default=None, null=True, blank=True) technology_id = models.CharField(max_length=255,default=None, null=True, blank=True)
tags_id = models.CharField(max_length=255, default=None, null=True, blank=True) tags_id = models.CharField(max_length=255, default=None, null=True, blank=True)
class Meta: class Meta:
...@@ -49,17 +49,35 @@ class News(models.Model): ...@@ -49,17 +49,35 @@ class News(models.Model):
def get_technology(self): def get_technology(self):
if self.technology_id: if self.technology_id:
return WpEsiTechnology.objects.get(id=self.technology_id) return WpEsiTechnology.objects.filter(id__in=json.loads(self.technology_id))
return None
def get_technology_json(self):
tech = self.get_technology()
if tech:
return json.dumps([{'text': i.name, 'value': i.id} for i in tech])
return None return None
def get_function(self): def get_function(self):
if self.function_id: if self.function_id:
return WpEsiFunction.objects.get(id=self.function_id) return WpEsiFunction.objects.filter(id__in=json.loads(self.function_id))
return None
def get_function_json(self):
func = self.get_function()
if func:
return json.dumps([{'text': i.name, 'value': i.id} for i in func])
return None return None
def get_industry(self): def get_industry(self):
if self.industry_id: if self.industry_id:
return WpEsiIndustry.objects.get(id=self.industry_id) return WpEsiIndustry.objects.filter(id__in=json.loads(self.industry_id))
return None
def get_industry_json(self):
ind = self.get_industry()
if ind:
return json.dumps([{'text': i.name, 'value': i.id} for i in ind])
return None return None
def get_radar(self): def get_radar(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