import json
from check1.models import check
class load():
json_data = open('db.json')
dates = json.load(json_data)
for date in dates:
ss = check(title=date['title'], status=1)
ss.save()
json_data.close()
File "/home/alexander/my_projects/testing/env/lib/python3.5/site-packages/django/db/models/base.py", line 700, in save
force_update=force_update, update_fields=update_fields)
File "/home/alexander/my_projects/testing/env/lib/python3.5/site-packages/parler/models.py", line 855, in save_base
assert self.language_code is not None, ""\
AssertionError: No language is set or detected for this TranslatableModelMixin.
Is the translations system initialized?
import json
from .check1.models import *
class load():
json_data = open('db.json')
dates = json.load(json_data)
for date in dates:
print(date['pk'])
ss = check(title=date['pk'], master_id=date['pk'])
ss.save()
json_data.close()
INSTALLED_APPS = [
...
'check1.apps.CheckConfig',
'parler',
]
File "<console>", line 1, in <module>
File "/home/alexander/my_projects/testing/testing/load.py", line 3, in <module>
from .check1.models import *
SystemError: Parent module '' not loaded, cannot perform relative import
from django.db import models
class check(models.Model):
alias = models.CharField(max_length=100)
status = models.BooleanField()
title = models.CharField(max_length=100)
description = models.TextField()
from django.db import models
from parler.models import TranslatableModel, TranslatedFields
class check(TranslatableModel):
alias = models.CharField(max_length=100)
status = models.BooleanField()
translations = TranslatedFields(
title=models.CharField(max_length=100),
description=models.TextField(),
)
from django.db import models
from parler.models import TranslatableModel, TranslatedFields
class check(TranslatableModel):
alias = models.CharField(max_length=100)
status = models.BooleanField()
translations = TranslatedFields(
title=models.CharField(max_length=100),
description=models.TextField(),
)
...
from parler.forms import TranslatableModelForm, TranslatedField
....
class NewsForm(TranslatableModelForm):
image = TranslatedField(form_class=MultiFileField(max_num=5, required=False, label="Изображение"))
images_for_delete = forms.CharField(widget=forms.HiddenInput(), label="", required=False, max_length=200)
class Meta:
model = New
fields = (
'title', 'alias', 'text', 'short_text', 'category',
'meta_keywords', 'meta_descriptions', 'status',
'create_date', 'image',
)
....