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

add multiple choice to edit view

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