added missing history field to Company

This commit is contained in:
Sam
2021-02-04 11:22:25 +00:00
parent 12c0ddcbe8
commit e30af924f0
3 changed files with 8 additions and 2 deletions

View File

@@ -44,7 +44,8 @@ class Company(models.Model):
# internal # internal
created = models.DateTimeField('date of creation', auto_now_add=True) created = models.DateTimeField('date of creation', auto_now_add=True)
updated = models.DateTimeField('date last update', auto_now=True) updated = models.DateTimeField('date last update', auto_now=True)
creator = models.ForeignKey('core.CustomUser', on_delete=models.DO_NOTHING, null=True, related_name='creator') creator = models.ForeignKey('core.CustomUser', on_delete=models.DO_NOTHING, null=True, related_name='company_creator')
history = models.ForeignKey('history.HistorySync', on_delete=models.DO_NOTHING, null=True, related_name='company_history')
def __str__(self): def __str__(self):
return self.company_name return self.company_name

View File

@@ -17,6 +17,7 @@ from rest_framework.generics import UpdateAPIView
from rest_framework.decorators import api_view, permission_classes from rest_framework.decorators import api_view, permission_classes
from companies.models import Company from companies.models import Company
from history.models import HistorySync
from . import models from . import models
from . import serializers as core_serializers from . import serializers as core_serializers
@@ -109,6 +110,9 @@ def load_coop_managers(request):
logging.info(f"Reading contents of {csv_file.name}") logging.info(f"Reading contents of {csv_file.name}")
decoded_file = csv_file.read().decode('utf-8').splitlines() decoded_file = csv_file.read().decode('utf-8').splitlines()
csv_reader = csv.DictReader(decoded_file, delimiter=',') csv_reader = csv.DictReader(decoded_file, delimiter=',')
# create historysync instance
history = HistorySync.objects.create(sync_date=datetime.datetime.now(), quantity=len(decoded_file))
coop_counter = 0 coop_counter = 0
user_counter = 0 user_counter = 0
for row in csv_reader: for row in csv_reader:
@@ -122,6 +126,7 @@ def load_coop_managers(request):
'short_name': row['nombre-corto'].strip(), 'short_name': row['nombre-corto'].strip(),
'shop': bool(row['es-tienda'].strip()), 'shop': bool(row['es-tienda'].strip()),
'shop_link': row['url'].strip(), 'shop_link': row['url'].strip(),
'history': history,
} }
coop = Company.objects.create(**coop_data) coop = Company.objects.create(**coop_data)
logging.info(f"Created Coop: {coop_data}") logging.info(f"Created Coop: {coop_data}")

View File

@@ -7,7 +7,7 @@ class HistorySync(models.Model):
Keeps an historic record of the importation of products for a company Keeps an historic record of the importation of products for a company
""" """
company = models.ForeignKey('companies.Company', on_delete=models.DO_NOTHING, null=True) company = models.ForeignKey('companies.Company', on_delete=models.DO_NOTHING, null=True, related_name='history_company')
rss_url = models.URLField('URL del feed', null=True, blank=True) rss_url = models.URLField('URL del feed', null=True, blank=True)
sync_date = models.DateTimeField('Fecha de lanzamiento', null=True) sync_date = models.DateTimeField('Fecha de lanzamiento', null=True)
result = models.TextField('Resultado', null=True, blank=True) result = models.TextField('Resultado', null=True, blank=True)