Использование готовой базы Djando - Python
Формулировка задачи:
Как сгенерить модели из готовой худо-бедно описано (пришлось убрать схемы из постгре, но и ладно).
А вот дальше как быть не понятно. Модели сгенерились:
После исправления ключей, подключил модели к админке:
В админке баз он не видит.
Ага, нужно сделать миграцию, что бы он где-то на внутреннем уровне теперь эти модели проассоциировал с реальными таблицами, подумал я.
Но это привело к созданию новых таблиц вида (имя проекта_имя таблицы). Из админки видно именно новые таблицы. Но мне как-то надо заставить его использовать существующие... как?
# This is an auto-generated Django model module. # You'll have to do the following manually to clean this up: # * Rearrange models' order # * Make sure each model has one field with primary_key=True # * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table # Feel free to rename the models, but don't rename db_table values or field names. from __future__ import unicode_literals from django.db import models class DimEmployee(models.Model): employee_sid = models.AutoField(primary_key=True) first_name = models.CharField(max_length=64, blank=True, null=True) last_name = models.CharField(max_length=64, blank=True, null=True) middle_name = models.CharField(max_length=64, blank=True, null=True) login = models.CharField(max_length=64, blank=True, null=True) pwd = models.CharField(max_length=256, blank=True, null=True) is_active = models.CharField(max_length=1) sysdate = models.DateTimeField(blank=True, null=True) class Meta: managed = False db_table = 'dim_employee' class DimPatient(models.Model): patient_sid = models.AutoField(primary_key=True) patient_bk = models.CharField(max_length=64, blank=True, null=True) first_name = models.CharField(max_length=64, blank=True, null=True) last_name = models.CharField(max_length=64, blank=True, null=True) middle_name = models.CharField(max_length=64, blank=True, null=True) sex = models.CharField(max_length=1, blank=True, null=True) dt_birth = models.CharField(max_length=64, blank=True, null=True) dt_death = models.CharField(max_length=64, blank=True, null=True) spdul_code = models.CharField(max_length=64, blank=True, null=True) spdul_num = models.CharField(max_length=64, blank=True, null=True) snils = models.CharField(max_length=64, blank=True, null=True) oms_num = models.CharField(max_length=64, blank=True, null=True) dms_num = models.CharField(max_length=64, blank=True, null=True) sysdate = models.DateTimeField(blank=True, null=True) class Meta: managed = False db_table = 'dim_patient' class DimSensor(models.Model): sensid = models.CharField(primary_key=True, max_length=64) sensor_type_sid = models.IntegerField(blank=True, null=True) class Meta: managed = False db_table = 'dim_sensor' class DirAction(models.Model): action_sid = models.IntegerField(primary_key=True) action_name = models.CharField(max_length=256, blank=True, null=True) class Meta: managed = False db_table = 'dir_action' class DirDep(models.Model): dep_sid = models.AutoField(primary_key=True) lpu_sid = models.IntegerField(blank=True, null=True) dep_name = models.CharField(max_length=256, blank=True, null=True) class Meta: managed = False db_table = 'dir_dep' class DirLpu(models.Model): lpu_sid = models.AutoField(primary_key=True) lpu_name = models.CharField(max_length=256, blank=True, null=True) class Meta: managed = False db_table = 'dir_lpu' class DirMsgDataAttr(models.Model): msg_data_attr_sid = models.AutoField(primary_key=True) attr_name = models.CharField(max_length=64, blank=True, null=True) attr_note = models.CharField(max_length=256, blank=True, null=True) class Meta: managed = False db_table = 'dir_msg_data_attr' class DirPost(models.Model): post_sid = models.AutoField(primary_key=True) post_name = models.CharField(max_length=256, blank=True, null=True) class Meta: managed = False db_table = 'dir_post' class DirRole(models.Model): role_sid = models.IntegerField(primary_key=True) role_name = models.CharField(max_length=64, blank=True, null=True) class Meta: managed = False db_table = 'dir_role' class DirSensorType(models.Model): sensor_type_sid = models.AutoField(primary_key=True) sensor_type_name = models.CharField(max_length=256, blank=True, null=True) sensor_note = models.CharField(max_length=256, blank=True, null=True) class Meta: managed = False db_table = 'dir_sensor_type' class DirSpdul(models.Model): spdul_code = models.CharField(primary_key=True, max_length=64) name = models.CharField(max_length=256) short_name = models.CharField(max_length=64, blank=True, null=True) template = models.CharField(max_length=64, blank=True, null=True) commnt = models.CharField(max_length=256, blank=True, null=True) class Meta: managed = False db_table = 'dir_spdul' class FactActionAlarms(models.Model): action_alarms_sid = models.AutoField() condition_sid = models.IntegerField(blank=True, null=True) patient_sid = models.BigIntegerField(blank=True, null=True) action_sid = models.IntegerField(blank=True, null=True) sensid = models.CharField(max_length=64, blank=True, null=True) msg_sid = models.BigIntegerField(blank=True, null=True) sysdate = models.DateTimeField(blank=True, null=True) class Meta: managed = False db_table = 'fact_action_alarms' class FactMsgData(models.Model): msg_sid = models.AutoField(primary_key=True) sensid = models.CharField(max_length=64, blank=True, null=True) dhubid = models.CharField(max_length=64, blank=True, null=True) cachedbid = models.CharField(max_length=64, blank=True, null=True) time = models.IntegerField(blank=True, null=True) start = models.IntegerField(blank=True, null=True) stop = models.IntegerField(blank=True, null=True) json_data = models.TextField(blank=True, null=True) # This field type is a guess. sysdate = models.DateTimeField(blank=True, null=True) class Meta: managed = False db_table = 'fact_msg_data' class LinkCondition(models.Model): condition_sid = models.AutoField(primary_key=True) patient_sid = models.BigIntegerField(blank=True, null=True) rule_sid = models.IntegerField(blank=True, null=True) action_sid = models.IntegerField(blank=True, null=True) attr_val_start = models.IntegerField(blank=True, null=True) attr_val_end = models.IntegerField(blank=True, null=True) length_start = models.IntegerField(blank=True, null=True) length_end = models.IntegerField(blank=True, null=True) condition_order = models.IntegerField(blank=True, null=True) sysdate = models.DateTimeField(blank=True, null=True) class Meta: managed = False db_table = 'link_condition' class LinkEmpLink(models.Model): emp_link_sid = models.AutoField(primary_key=True) lpu_sid = models.IntegerField(blank=True, null=True) employee_sid = models.IntegerField(blank=True, null=True) dep_sid = models.IntegerField(blank=True, null=True) post_sid = models.IntegerField(blank=True, null=True) role_sid = models.IntegerField(blank=True, null=True) sysdate = models.DateTimeField(blank=True, null=True) class Meta: managed = False db_table = 'link_emp_link' class LinkPatientLink(models.Model): patient_link_sid = models.AutoField() emp_link_sid = models.IntegerField(blank=True, null=True) room_bed_link_sid = models.IntegerField(blank=True, null=True) dep_sid = models.IntegerField(blank=True, null=True) employee_sid = models.IntegerField(blank=True, null=True) patient_sid = models.BigIntegerField(blank=True, null=True) lpu_sid = models.IntegerField(blank=True, null=True) date_link = models.DateField(blank=True, null=True) date_unlink = models.DateField(blank=True, null=True) sysdate = models.DateTimeField(blank=True, null=True) class Meta: managed = False db_table = 'link_patient_link' class LinkRoomBedLink(models.Model): room_bed_link_sid = models.AutoField(primary_key=True) lpu_id = models.IntegerField(blank=True, null=True) dep_sid = models.IntegerField(blank=True, null=True) room_num = models.CharField(max_length=64, blank=True, null=True) bed_num = models.CharField(max_length=64, blank=True, null=True) sysdate = models.DateTimeField(blank=True, null=True) class Meta: managed = False db_table = 'link_room_bed_link' class LinkRuleLink(models.Model): rule_sid = models.AutoField(primary_key=True) action_sid = models.IntegerField(blank=True, null=True) msg_data_attr_sid = models.IntegerField(blank=True, null=True) def_attr_val_start = models.IntegerField(blank=True, null=True) def_attr_val_end = models.IntegerField(blank=True, null=True) def_length_start = models.IntegerField(blank=True, null=True) def_length_end = models.IntegerField(blank=True, null=True) condition_order = models.IntegerField(blank=True, null=True) sysdate = models.DateTimeField(blank=True, null=True) class Meta: managed = False db_table = 'link_rule_link' class LinkSensorRoomLink(models.Model): sensor_room_link_sid = models.AutoField() room_bed_link_sid = models.IntegerField(blank=True, null=True) sensid = models.CharField(max_length=64, blank=True, null=True) sysdate = models.DateTimeField(blank=True, null=True) class Meta: managed = False db_table = 'link_sensor_room_link'
from devreg.models import DimEmployee from devreg.models import DimPatient from devreg.models import DimSensor from devreg.models import DirAction from devreg.models import DirDep from devreg.models import DirLpu from devreg.models import DirMsgDataAttr from devreg.models import DirPost from devreg.models import DirRole from devreg.models import DirSensorType from devreg.models import DirSpdul from devreg.models import FactActionAlarms from devreg.models import FactMsgData from devreg.models import LinkCondition from devreg.models import LinkEmpLink from devreg.models import LinkPatientLink from devreg.models import LinkRoomBedLink from devreg.models import LinkRuleLink from devreg.models import LinkSensorRoomLink admin.site.register(DimEmployee) admin.site.register(DimPatient) admin.site.register(DimSensor) admin.site.register(DirAction) admin.site.register(DirDep) admin.site.register(DirLpu) admin.site.register(DirMsgDataAttr) admin.site.register(DirPost) admin.site.register(DirRole) admin.site.register(DirSensorType) admin.site.register(DirSpdul) admin.site.register(FactActionAlarms) admin.site.register(FactMsgData) admin.site.register(LinkCondition) admin.site.register(LinkEmpLink) admin.site.register(LinkPatientLink) admin.site.register(LinkRoomBedLink) admin.site.register(LinkRuleLink) admin.site.register(LinkSensorRoomLink)
Решение задачи: «Использование готовой базы Djando»
textual
Листинг программы
class DimSensor(models.Model): sensid = models.CharField(primary_key=True, max_length=64) sensor_type_sid = models.IntegerField(blank=True, null=True) class Meta: managed = False db_table = 'dim_sensor'
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д