Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8794513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:15:43+00:00 2026-06-13T23:15:43+00:00

I saw mentions on here of the ZipCode database project for computing distance between

  • 0

I saw mentions on here of the ZipCode database project for computing distance between two zipcodes. I was able to upload the csv file successfully to my database using Django and sqlite3. However, now I am not able to perform queries with anything except the zipcode itself (city and state don’t work). I thought it was because the csv file had quotes around the city and state, so I tried uploaded the file taking out all of the quotes. No luck. Then I thought the encoding was off, so I uploaded again making sure that it was encoded in utf-8. Again, no luck. Does anyone have experience with this database?
The database is at http://zips.sourceforge.net/
And the way I am loading it is based off of http://mitchfournier.com/2011/10/11/how-to-import-a-csv-or-tsv-file-into-a-django-model/
I shied away from geodjango because it seemed like overkill for what I want to do. Any help would be greatly appreciated.

Here is the code:

For my zipcode class:

class ZipCode(models.Model):
    zipcode=models.CharField(max_length=5)
statecode=models.CharField(max_length=2)
lat=models.CharField(max_length=9)
long=models.CharField(max_length=9)
city=models.CharField(max_length=64)
state=models.CharField(max_length=32)
create_date=models.DateTimeField(default=datetime.datetime.now)
def __unicode__(self):
    return "%s %s %s" %(self.city,self.statecode,self.zipcode)

Then I have a class for Descriptions, here I want to convert city and states to zipcodes, ideally

class Descriptions(models.Model):
name=models.CharField(max_length=50)
website=models.CharField(max_length=50,blank=True)
street1=models.CharField(max_length=50,blank=True)
street2=models.CharField(max_length=50,blank=True)
city=models.CharField(max_length=50,blank=True)
state=models.CharField(max_length=50,blank=True)
zip=models.CharField(max_length=5,blank=True)
description=models.TextField()
areas_related=models.TextField()
add_area=models.CharField(max_length=50,blank=True)
federal=models.NullBooleanField(null=True)
def get_zip(self):
    if self.city and self.state:
        real_zip=ZipCode.objects.filter(statecode=self.state) ####note this is not the real query I want to do, but even this returns None
                    ###alternatively, if I do (zip=self.zipcode) I will get an object returned
        return real_zip
    def __unicode__(self):
    return u'%s %s %s %s %s %s %s %s %s %s %s' %(self.name,self.website,self.street1,
    self.street2,self.city,self.state,self.zip,self.description,self.add_area, self.federal, self.get_zip())

For the uploading file:

csv_filepathname='/Users/sam/Documents/service/mysite/zips.csv'
your_djangoproject_home='/Users/sam/Documents/service/mysite/mysite'

import sys,os

sys.path.append(your_djangoproject_home)
os.environ['DJANGO_SETTINGS_MODULE']='settings'

from southtut.models import ZipCode

import csv
dataReader = csv.reader(open(csv_filepathname), delimiter=',', quotechar='"')
for row in dataReader:
    if row[0]!='ZIPCODE':
        zipcode=ZipCode()
        zipcode.zipcode=row[0]
        zipcode.statecode=row[1]    
        zipcode.lat=row[2]          
        zipcode.long=row[3]
        zipcode.city=row[4]     
        zipcode.state=row[5]            
        zipcode.save()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:15:44+00:00Added an answer on June 13, 2026 at 11:15 pm

    Used a different database. Still not sure as to why the one I had wasn’t working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw some code when studying the open source project: here . But I
On a screen-recording github project here , I saw one line of code: mCaptureScreenInput
I saw that even by writing separate commands, we can combine two different types
I saw comment If you have 50 million values between 10 and 15 characters
I saw a similar question being posted here, yet it did not help me
I saw a similar question, and it mentions about the change in December 2011,
In another Q I saw someone mention LOGO and it reminded me of some
I saw some websites that (for example): if you want to view your message
I saw the docs on the Instagram developers page. http://instagram.com/developer/endpoints/ But I want to
I saw many threads with this tittle, but no one really speak about reuse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.