Re: Pre-loading static data into database table

2017-06-29 Thread John Thomas
Hi Rich,

419 is not that many.  I'd probably do that via a Python shell.  import
models.Cities  for item in lists_of_lists_of_419  temp =
Cities(city+name=item[0], county_name=item[1]) temp.save()


John Thomas
310-947-8572

On Thu, Jun 29, 2017 at 11:16 AM, Rich Shepard 
wrote:

>   Reading
> <https://docs.djangoproject.com/en/1.11/ref/migration-operat
> ions/#django.db.migrations.operations.RunSQL>
> tells me that runSQL allows arbitrary SQL to run on the database ... except
> for the postgres backend: "On most database backends (all but PostgreSQL),
> Django will split the SQL into individual statements prior to executing
> them."
>
>   I want to insert data into the two columns of the database. The model
> reads:
>
> class Cities (models.Model):
> city_name=models.CharField(max_length=24, unique=True)
> county_name=models.CharField(max_length=12, unique=True)
>
> and I have a list of 419 pairs of names I want to pre-load into this
> database table. The rows contain the two variables; e.g.,
>   Bend,Deschutes
>   Birkenfeld,Columbia
>   Blachly,Lane
>   Black Butte Ranch,Deschutes
>
>   So, using a postgres back end can I write,
>
>   migrations.RunSQL("INSERT INTO Cities (city_name,county_name) VALUES
> ('Bend','Dechutes');")
>
> repeated for each row in the table (easy to do with emacs)? And, can I put
> this code in models.py after the classes?
>
> Rich
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/CAJ22gMA%3Dir3HGr3_7fjcWi9jxQ%2BaY8Rciies43MfD29D%3DxgVNA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding a lookup table

2017-06-28 Thread John Thomas
Could you create a City model and a County model and relate them one County
to many Cities?  I'm not sure how to populate those tables.

As an aside, where do you get your City to County data.  I've been meaning
to look for that data.  Do all cities cleanly break into one county?


John Thomas
310-947-8572

On Wed, Jun 28, 2017 at 9:55 AM, Rich Shepard 
wrote:

>   I want to add a lookup table to my application. The table will have two
> columns: city_name and county. This will allow me to return all rows for
> companies in a specific county (or all companies sorted by county). I know
> how to do this with SQL and want to learn how to implement this capability
> in django (1.11.2 currently installed). Pointers to the appropriate docs
> much appreciated.
>
> Rich
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/CAJ22gMDeSMPOnUAGoXs3990C_LjawtwLDB1f4pkReoWOGMbb2w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


New User Tips?

2015-08-25 Thread John Thomas
Hi Django-Users:

I am starting a project.  I just saw the tip below.  I was wondering if you
would share other tips you have.

   1. I _always_ start every project with a custom User model, to avoid
   this problem ["this problem" = "difficult to transfer to a custom user
   model."]


John Thomas

-- 
If you are not the intended recipient of this message, please promptly 
notify the sender of the transmission error, delete this message and do not 
disclose or make improper use of it. Electronic messages are not 
necessarily secure or error-free and can contain viruses, and the sender is 
not liable for any of these occurrences.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJ22gMD11fRGrCr-oE89Y1dCgEK2TUc%2BFc7batbdzTk3qf9T9A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.