Discussion:
How I can insert data into database automaticaly
(too old to reply)
Informatico de Neurodesarrollo
2018-12-04 17:08:25 UTC
Permalink
Hello:

I am a beginner on Django. I wish develop a web app with Django 2.1.3
and Postgres.

I have to create my project and later, make migrations on my data base,
but I need introduce some data previously into my database like all
provinces and other a lot of information's, which don't want introduce 
a lot of data that I want put into them without insert one and other time.

 Any one can help me
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.


--
Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/05e29177-9354-23d0-31b1-73cf7cae947b%40infomed.sld.cu.
For more options, visit https://groups.google.com/d/optout.
soumyajit banerjee
2018-12-04 17:21:13 UTC
Permalink
you can use faker library, for insert dummy data into your model.

On Tue, Dec 4, 2018 at 10:39 PM Informatico de Neurodesarrollo <
Post by Informatico de Neurodesarrollo
I am a beginner on Django. I wish develop a web app with Django 2.1.3
and Postgres.
I have to create my project and later, make migrations on my data base,
but I need introduce some data previously into my database like all
provinces and other a lot of information's, which don't want introduce
a lot of data that I want put into them without insert one and other time.
Any one can help me
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.
--
Este mensaje le ha llegado mediante el servicio de correo electronico que
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema
Nacional de Salud. La persona que envia este correo asume el compromiso de
usar el servicio a tales fines y cumplir con las regulaciones establecidas
Infomed: http://www.sld.cu/
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/05e29177-9354-23d0-31b1-73cf7cae947b%40infomed.sld.cu
.
For more options, visit https://groups.google.com/d/optout.
--
Soumyajit Banerjee
Tech Analyst
Infosys
m: 9903675354
w: www.infosys.com e: ***@gmail.com
<https://www.facebook.com/recklessLYF>
<https://www.linkedin.com/in/soumyajit-banerjee-11992b25/>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAG8c6EFEzSDKH_ika33M3Hy5EHL544%2Bb9%2BFHbrfBAYHEGB9VMQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Gerson David Vizquel Alemán
2018-12-04 17:51:06 UTC
Permalink
Hola Jesus, la información que requieres cargar inicialmente en la base de
datos es información fake o real?

El martes, 4 de diciembre de 2018, 13:09:04 (UTC-4), Informatico de
Post by Informatico de Neurodesarrollo
I am a beginner on Django. I wish develop a web app with Django 2.1.3
and Postgres.
I have to create my project and later, make migrations on my data base,
but I need introduce some data previously into my database like all
provinces and other a lot of information's, which don't want introduce
a lot of data that I want put into them without insert one and other time.
Any one can help me
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.
--
Este mensaje le ha llegado mediante el servicio de correo electronico que
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema
Nacional de Salud. La persona que envia este correo asume el compromiso de
usar el servicio a tales fines y cumplir con las regulaciones establecidas
Infomed: http://www.sld.cu/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/982e6114-a6ea-423c-938c-8865d0652fdd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mark Phillips
2018-12-05 01:29:24 UTC
Permalink
James,

Take a look at this page -
https://docs.djangoproject.com/en/2.1/howto/initial-data/

Be sure to backup your database before you migrate just in case.

Also, sometimes it is faster and easier to just drop the project's database
and restore from a backup than to fiddle with the initial data. Depends on
the situation, of course.

Mark

On Tue, Dec 4, 2018 at 10:51 AM Gerson David Vizquel Alemán <
Post by Gerson David Vizquel Alemán
Hola Jesus, la información que requieres cargar inicialmente en la base de
datos es información fake o real?
El martes, 4 de diciembre de 2018, 13:09:04 (UTC-4), Informatico de
Post by Informatico de Neurodesarrollo
I am a beginner on Django. I wish develop a web app with Django 2.1.3
and Postgres.
I have to create my project and later, make migrations on my data base,
but I need introduce some data previously into my database like all
provinces and other a lot of information's, which don't want introduce
a lot of data that I want put into them without insert one and other time.
Any one can help me
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.
--
Este mensaje le ha llegado mediante el servicio de correo electronico que
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema
Nacional de Salud. La persona que envia este correo asume el compromiso de
usar el servicio a tales fines y cumplir con las regulaciones establecidas
Infomed: http://www.sld.cu/
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/982e6114-a6ea-423c-938c-8865d0652fdd%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/982e6114-a6ea-423c-938c-8865d0652fdd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEqej2MLbUrrHgvUOJ-R_vVzN-Zkgw%2Bk%2BaLq6rXDXfUPpz84hw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Informatico de Neurodesarrollo
2018-12-06 18:28:57 UTC
Permalink
Saludos Gerson:

Es real, trabajo en salud y estoy trabajando en un sistema para el
control de medicamentos y necesito tener ya en la base de datos las
provincias, sus municipios, áreas de salud, medicamentos controlados,
etc. con los que voy a trabajar y cuando lo termine será puesto es todas
las farmacias del municipio donde trabajo (Cárdenas,Matanzas,Cuba). como
decía, estoy comenzando en Django y quiero hacerlo porque deseo trabajar
sobre software libre y trabajo con linux desde el 2004 (más orientado a
servidores).

In english:

I am working in Cuban's  system health  care and I am began work on a
web app apply to a medicine's control and I need put into the database
to go ahead on my app, some data like all province, each municipals 
regions, cities and other information (at time to deploy my app in
production site, I save time and work to introduce a lot of data time
after time ).

PD Apologist my english and I answered to Gerson's email address.
PD Disculpen  respondí al correo de Gerson, no a la lista.
Post by Gerson David Vizquel Alemán
Hola Jesus, la información que requieres cargar inicialmente en la
base de datos es información fake o real?
El martes, 4 de diciembre de 2018, 13:09:04 (UTC-4), Informatico de
I am a beginner on Django. I wish develop a web app with Django 2.1.3
and Postgres.
I have to create my project and later, make migrations on my data base,
but I need introduce some data previously into my database like all
provinces and other a lot of information's, which don't want introduce
a lot of data that I want put into them without insert one and other time.
  Any one can help me
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.
--
Este mensaje le ha llegado mediante el servicio de correo
electronico que ofrece Infomed para respaldar el cumplimiento de
las misiones del Sistema Nacional de Salud. La persona que envia
este correo asume el compromiso de usar el servicio a tales fines
y cumplir con las regulaciones establecidas
Infomed: http://www.sld.cu/
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/982e6114-a6ea-423c-938c-8865d0652fdd%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/982e6114-a6ea-423c-938c-8865d0652fdd%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.



--
Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bab14959-46fd-9702-6d10-715794bf9c01%40infomed.sld.cu.
For more options, visit https://groups.google.com/d/optout.
Mike Dewhirst
2018-12-06 21:31:11 UTC
Permalink
Jesús

Where is your data right now?

If you can put it into a separate database - or even a spreadsheet - it
can be automatically reloaded at any time.

There are two ways to do this. One is a data migration ...

https://docs.djangoproject.com/en/1.11/ref/migration-operations/#runpython

... and the other is a custom manage.py command ...

https://docs.djangoproject.com/en/1.11/howto/custom-management-commands/#module-django.core.management

In either case you write a function which uses Django's everyday tools
to insert data. If your data is in a flat file you can read it line by
line and extract the data you want, format it the way you want, run it
through any checks or tests you want then if it doesn't already exist
insert it.

I first used data migrations to insert reference data and worked out a
way to live with it. In effect, I had to insert 'return None' at a
strategic spot to prevent it running a second time.

Then I had a very complex data import with lots of m2m data represented
in a flat Excel spreadsheet and that was too ugly for a data migration
so I put in some study time and eventually built a manage.py command.

However, a possible third way might be found here ...

https://djangopackages.org/grids/g/countries/

I haven't used any so I can't tell you much.

Good luck

Mike
Post by Informatico de Neurodesarrollo
Es real, trabajo en salud y estoy trabajando en un sistema para el
control de medicamentos y necesito tener ya en la base de datos las
provincias, sus municipios, áreas de salud, medicamentos controlados,
etc. con los que voy a trabajar y cuando lo termine será puesto es
todas las farmacias del municipio donde trabajo
(Cárdenas,Matanzas,Cuba). como decía, estoy comenzando en Django y
quiero hacerlo porque deseo trabajar sobre software libre y trabajo
con linux desde el 2004 (más orientado a servidores).
I am working in Cuban's  system health  care and I am began work on  a
web app apply to a medicine's control and I need put into the database
to go ahead on my app, some data like all province, each municipals 
regions, cities and other information (at time to deploy my app in
production site, I save time and work to introduce a lot of data time
after time ).
PD Apologist my english and I answered to Gerson's email address.
PD Disculpen  respondí al correo de Gerson, no a la lista.
Hola Jesus, la información que requieres cargar inicialmente en la
base de datos es información fake o real?
El martes, 4 de diciembre de 2018, 13:09:04 (UTC-4), Informatico de
I am a beginner on Django. I wish develop a web app with Django 2.1.3
and Postgres.
I have to create my project and later, make migrations on my data base,
but I need introduce some data previously into my database like all
provinces and other a lot of information's, which don't want introduce
a lot of data that I want put into them without insert one and other time.
  Any one can help me
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.
--
Este mensaje le ha llegado mediante el servicio de correo
electronico que ofrece Infomed para respaldar el cumplimiento de
las misiones del Sistema Nacional de Salud. La persona que envia
este correo asume el compromiso de usar el servicio a tales fines
y cumplir con las regulaciones establecidas
Infomed: http://www.sld.cu/
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/982e6114-a6ea-423c-938c-8865d0652fdd%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/982e6114-a6ea-423c-938c-8865d0652fdd%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/bab14959-46fd-9702-6d10-715794bf9c01%40infomed.sld.cu
<https://groups.google.com/d/msgid/django-users/bab14959-46fd-9702-6d10-715794bf9c01%40infomed.sld.cu?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2ffb8840-8c59-8ba6-45a6-2034f24e7fba%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.
Informatico de Neurodesarrollo
2018-12-07 15:43:15 UTC
Permalink
Thanks Mike:

My data are in different formats, but I don't care pass it by hand once
time.

Previously, I know that I need make migrations my model into "postgres"
database creating the hole table but empty

My interest will be learn one way put a previous data into my database,
before going on with the develop of my app.

eg.:

In models.py :

class Provincia(models.Model):
    idProvincia = models.CharField(max_length=2, primary_key=true)
    ProvinciaName = models.CharField(max_length=30)

    class Admin:pass

    def __str__(self):
        return self.ProvinciaName

And the data that I need put into them are:

In table:

Provincia:

    Insert(idProvincia = 01,  ProvinciaName = "Pinar del Río")

    Insert(idProvincia = 02,  ProvinciaName = "La Habana")

    ...

TIA
Post by Mike Dewhirst
Jesús
Where is your data right now?
If you can put it into a separate database - or even a spreadsheet -
it can be automatically reloaded at any time.
There are two ways to do this. One is a data migration ...
https://docs.djangoproject.com/en/1.11/ref/migration-operations/#runpython
... and the other is a custom manage.py command ...
https://docs.djangoproject.com/en/1.11/howto/custom-management-commands/#module-django.core.management
In either case you write a function which uses Django's everyday tools
to insert data. If your data is in a flat file you can read it line by
line and extract the data you want, format it the way you want, run it
through any checks or tests you want then if it doesn't already exist
insert it.
I first used data migrations to insert reference data and worked out a
way to live with it. In effect, I had to insert 'return None' at a
strategic spot to prevent it running a second time.
Then I had a very complex data import with lots of m2m data
represented in a flat Excel spreadsheet and that was too ugly for a
data migration so I put in some study time and eventually built a
manage.py command.
However, a possible third way might be found here ...
https://djangopackages.org/grids/g/countries/
I haven't used any so I can't tell you much.
Good luck
Mike
Post by Informatico de Neurodesarrollo
Es real, trabajo en salud y estoy trabajando en un sistema para el
control de medicamentos y necesito tener ya en la base de datos las
provincias, sus municipios, áreas de salud, medicamentos controlados,
etc. con los que voy a trabajar y cuando lo termine será puesto es
todas las farmacias del municipio donde trabajo
(Cárdenas,Matanzas,Cuba). como decía, estoy comenzando en Django y
quiero hacerlo porque deseo trabajar sobre software libre y trabajo
con linux desde el 2004 (más orientado a servidores).
I am working in Cuban's  system health  care and I am began work on 
a web app apply to a medicine's control and I need put into the
database to go ahead on my app, some data like all province, each
municipals  regions, cities and other information (at time to deploy
my app in production site, I save time and work to introduce a lot of
data time after time ).
PD Apologist my english and I answered to Gerson's email address.
PD Disculpen  respondí al correo de Gerson, no a la lista.
Hola Jesus, la información que requieres cargar inicialmente en la
base de datos es información fake o real?
El martes, 4 de diciembre de 2018, 13:09:04 (UTC-4), Informatico de
    I am a beginner on Django. I wish develop a web app with Django
    2.1.3
    and Postgres.
    I have to create my project and later, make migrations on my data
    base,
    but I need introduce some data previously into my database like all
    provinces and other a lot of information's, which don't want
    introduce
    a lot of data that I want put into them without insert one and
    other time.
      Any one can help me
    --
    Ing. Jesús Reyes Piedra
    Admin Red Neurodesarrollo,Cárdenas
    La caja decía:"Requiere windows 95 o superior"...
    Entonces instalé LINUX.
    --     Este mensaje le ha llegado mediante el servicio de correo
    electronico que ofrece Infomed para respaldar el cumplimiento de
    las misiones del Sistema Nacional de Salud. La persona que envia
    este correo asume el compromiso de usar el servicio a tales fines
    y cumplir con las regulaciones establecidas
    Infomed: http://www.sld.cu/
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/982e6114-a6ea-423c-938c-8865d0652fdd%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/982e6114-a6ea-423c-938c-8865d0652fdd%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/bab14959-46fd-9702-6d10-715794bf9c01%40infomed.sld.cu
<https://groups.google.com/d/msgid/django-users/bab14959-46fd-9702-6d10-715794bf9c01%40infomed.sld.cu?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.


--
Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/544f6f65-a6cb-6658-6cbf-6a835ee27936%40infomed.sld.cu.
For more options, visit https://groups.google.com/d/optout.
Mike Dewhirst
2018-12-08 05:38:15 UTC
Permalink
On Saturday, December 8, 2018 at 2:44:21 AM UTC+11, Informatico de
Post by Informatico de Neurodesarrollo
My data are in different formats, but I don't care pass it by hand once
time.
Once is enough, I agree.
Post by Informatico de Neurodesarrollo
Previously, I know that I need make migrations my model into "postgres"
database creating the hole table but empty
My interest will be learn one way put a previous data into my database,
before going on with the develop of my app.
You need a reference list of values you can re-import not just for
development but for information maintenance in future.

Maybe the government or postal service has a database you can read? Can you
maybe scrape what you want off the web to build your own list.

I think your models are going to be difficult to deal with if you try to
manage your own primary keys. For example, in your Provincia class you can
completely omit idProvincia. If you need a two-character abbreviation for a
province then put that in and use unique=True
Post by Informatico de Neurodesarrollo
idProvincia = models.CharField(max_length=2, primary_key=true)
ProvinciaName = models.CharField(max_length=30)
class Admin:pass
return self.ProvinciaName
You do not need to manually import and re-import your data directly in
PostgreSQL. That way madness lies - especially if you try to manage the
keys yourself. That is what the Django ORM is intended for.
Post by Informatico de Neurodesarrollo
Insert(idProvincia = 01, ProvinciaName = "Pinar del Río")
Insert(idProvincia = 02, ProvinciaName = "La Habana")
...
Here is a data import migration I wrote ...

# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import, division

from django.db import migrations, models
from refer.utils import import_ecfr_data

class Migration(migrations.Migration):

dependencies = [
# edit name of this file and put it into .migrations
# adjust dependency to last run migration, run migrate and get rid
of
# this file
('refer', '?previous migration?'),
]

operations = [
migrations.RunPython(
# edit refer.utils.import_ecfr_data to return None after it has
been run
import_ecfr_data,
),
]

You can see this template can be re-run as required and the callable
'import_ecfr_data()' can be edited to switch it off.

import_ecfr_data itself must have arguments like this ...

def import_ecfr_data(apps, schema_editor):

... because the migrations system expects any callable called by
migrations.RunPython to have those arguments. They are used in your
callable like this (an example from my project) to fetch your model classes
...

Jurisdiction = apps.get_model("regulation", "Jurisdiction")

and

db_alias = schema_editor.connection.alias

Then my input values exist in a file opened as 'infile' ...

with open(intext, 'r') as infile:
juris =
Jurisdiction.objects.using(db_alias).get(jurisdiction_code=jcode)
try:
legis = Regulation.objects.using(db_alias).get(
jurisdiction=juris,
field=field)
except Regulation.DoesNotExist:
... whatever is appropriate

In your case however with Provincia instead of 'get()' you might choose
'get_or_create()' or perhaps if DoesNotExist occurs you might create one
separately after processing some checks or reformatting.

In my case I don't ever have to think about key values. Django and Postgres
do it all for me. Much easier to think like a human being than a relational
database.

Summarising, assemble your reference data in a file then write an import
utility and call it from the migration system.

HTH
Post by Informatico de Neurodesarrollo
TIA
Post by Informatico de Neurodesarrollo
Jesús
Where is your data right now?
If you can put it into a separate database - or even a spreadsheet -
it can be automatically reloaded at any time.
There are two ways to do this. One is a data migration ...
https://docs.djangoproject.com/en/1.11/ref/migration-operations/#runpython
Post by Informatico de Neurodesarrollo
... and the other is a custom manage.py command ...
https://docs.djangoproject.com/en/1.11/howto/custom-management-commands/#module-django.core.management
Post by Informatico de Neurodesarrollo
In either case you write a function which uses Django's everyday tools
to insert data. If your data is in a flat file you can read it line by
line and extract the data you want, format it the way you want, run it
through any checks or tests you want then if it doesn't already exist
insert it.
I first used data migrations to insert reference data and worked out a
way to live with it. In effect, I had to insert 'return None' at a
strategic spot to prevent it running a second time.
Then I had a very complex data import with lots of m2m data
represented in a flat Excel spreadsheet and that was too ugly for a
data migration so I put in some study time and eventually built a
manage.py command.
However, a possible third way might be found here ...
https://djangopackages.org/grids/g/countries/
I haven't used any so I can't tell you much.
Good luck
Mike
Post by Informatico de Neurodesarrollo
Es real, trabajo en salud y estoy trabajando en un sistema para el
control de medicamentos y necesito tener ya en la base de datos las
provincias, sus municipios, áreas de salud, medicamentos controlados,
etc. con los que voy a trabajar y cuando lo termine será puesto es
todas las farmacias del municipio donde trabajo
(Cárdenas,Matanzas,Cuba). como decía, estoy comenzando en Django y
quiero hacerlo porque deseo trabajar sobre software libre y trabajo
con linux desde el 2004 (más orientado a servidores).
I am working in Cuban's system health care and I am began work on
a web app apply to a medicine's control and I need put into the
database to go ahead on my app, some data like all province, each
municipals regions, cities and other information (at time to deploy
my app in production site, I save time and work to introduce a lot of
data time after time ).
PD Apologist my english and I answered to Gerson's email address.
PD Disculpen respondí al correo de Gerson, no a la lista.
Post by Gerson David Vizquel Alemán
Hola Jesus, la información que requieres cargar inicialmente en la
base de datos es información fake o real?
El martes, 4 de diciembre de 2018, 13:09:04 (UTC-4), Informatico de
I am a beginner on Django. I wish develop a web app with Django 2.1.3
and Postgres.
I have to create my project and later, make migrations on my data base,
but I need introduce some data previously into my database like
all
Post by Informatico de Neurodesarrollo
Post by Informatico de Neurodesarrollo
Post by Gerson David Vizquel Alemán
provinces and other a lot of information's, which don't want introduce
a lot of data that I want put into them without insert one and other time.
Any one can help me
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.
-- Este mensaje le ha llegado mediante el servicio de correo
electronico que ofrece Infomed para respaldar el cumplimiento de
las misiones del Sistema Nacional de Salud. La persona que envia
este correo asume el compromiso de usar el servicio a tales fines
y cumplir con las regulaciones establecidas
Infomed: http://www.sld.cu/
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
<javascript:>
Post by Informatico de Neurodesarrollo
Post by Informatico de Neurodesarrollo
Post by Gerson David Vizquel Alemán
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/982e6114-a6ea-423c-938c-8865d0652fdd%40googlegroups.com
Post by Informatico de Neurodesarrollo
Post by Informatico de Neurodesarrollo
Post by Gerson David Vizquel Alemán
<
https://groups.google.com/d/msgid/django-users/982e6114-a6ea-423c-938c-8865d0652fdd%40googlegroups.com?utm_medium=email&utm_source=footer>.
Post by Informatico de Neurodesarrollo
Post by Informatico de Neurodesarrollo
Post by Gerson David Vizquel Alemán
For more options, visit https://groups.google.com/d/optout.
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
<javascript:>
Post by Informatico de Neurodesarrollo
Post by Informatico de Neurodesarrollo
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/bab14959-46fd-9702-6d10-715794bf9c01%40infomed.sld.cu
Post by Informatico de Neurodesarrollo
Post by Informatico de Neurodesarrollo
<
https://groups.google.com/d/msgid/django-users/bab14959-46fd-9702-6d10-715794bf9c01%40infomed.sld.cu?utm_medium=email&utm_source=footer>.
Post by Informatico de Neurodesarrollo
Post by Informatico de Neurodesarrollo
For more options, visit https://groups.google.com/d/optout.
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.
--
Este mensaje le ha llegado mediante el servicio de correo electronico que
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema
Nacional de Salud. La persona que envia este correo asume el compromiso de
usar el servicio a tales fines y cumplir con las regulaciones establecidas
Infomed: http://www.sld.cu/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/af82feeb-6415-4cbd-bf7f-96737be4df04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...