All,
    I agree with  Malcolm,  I could have done a much better job
detailing my question(s), so I will give it another shot.

Synopsis:

    I'm trying to develop a model for international locations that can
be associated with various content types such as an article,
advertisement, user, etc.  I would like to strike a balance between
user effort and ease of use by balancing my workload and the users.
Additionally,  I would like to give users the ability to show maps of
there locations, and localize some of there content based on there time
zone.
    I have prototyped a number of possible solutions, but haven't quite
worked out all of the kinks.  The question that I was initially trying
to pose was how to best store the UTC  time zone data.  I have been
experimenting with various data types starting with integers,  until I
discovered a number of locations that don't fall on an even number like
India  (UTC + 05:30).   I moved to a float and stored the UTC offset
for India as (5.5).   This didn't quite seem right so I  attempted to
store the Time Zone data in a Time Field without success
(00:00:00+05:30).  After  my initial post,  I continued to look for a
solution and discovered that when creating a time field you have to
specify the 'with time zone' parameter.  I manually created a test
table and was able to successfully store a  time with time zone data
(00:00:00+05:30).  Upon further research I discovered the strip time
module (time.strptime) that allows you to convert strings to time.
With this new information it seems logical to store the UTC offset data
as string then convert it to time when needed.  This would eliminate
the need for custom SQL, but would add the overhead of converting the
string to time.  At this point I'm still trying to sort out the best
method of storing and dealing with with this data.  What is the best
practice for this?  I'm also trying to flush out this model as a whole
so any suggestions to improve it would be greatly appreciated.


Here is my most recent prototype model:
===================================================================
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType

# Create your models here.


# Populate this table for the user.
class Country(models.Model):
    created_on = models.DateTimeField(auto_now_add=True)
    iso_code = models.CharField(maxlength=10, help_text="US, GB, AT,
BZ")
    name = models.CharField(maxlength=100, unique=True,
help_text="Example: United States, Canada, Germany")
    flag = models.ImageField(upload_to='flags', null=True, blank=True)
    def __str__(self):
        return (self.name)

    class Admin:
        pass

#Populate this table for the user:
class TimeZone(models.Model):
    created_on = models.DateTimeField(auto_now_add=True)
    std_deviation = models.CharField(maxlength=10)
    abbreviation = models.CharField(maxlength=10, help_text="Y, X, M")
    description = models.CharField(maxlength=100)
    observes_dst = models.BooleanField(default=True)
    dst_begins = models.DateTimeField()
    dst_end = models.DateTimeField()

    def __str__(self):
        return "%s, %s" %(self.std_deviation, self.description)

    class Admin:
        pass

# I ask the user to enter the finer details of the location.  I just
provide them with Country and Time Zone Information.
class Location(models.Model):
    created_by = models.ForeignKey(User)
    created_on = models.DateTimeField(auto_now_add=True)
    content_type = models.ForeignKey(ContentType)
    country = models.ForeignKey(Country)
    address_1 = models.CharField(maxlength=100, help_text="Example:
100N 1st Street.")
    address_2 = models.CharField(maxlength=100, blank=True, null=True,
help_text="Example: 100N 1st Street.")
    area = models.CharField(maxlength=100,  help_text="Eample: A City,
Town, or Village.")
    region = models.CharField(maxlength=100, help_text="Example: A
State, Provice, or Territory.")
    postal_code = models.CharField(maxlength=50, blank=True, null=True,
help_text="Example: 82072")
    latitude = models.FloatField(max_digits=11, decimal_places=6,
blank=True, null=True)
    longitude = models.FloatField(max_digits=11, decimal_places=6,
blank=True, null=True)
    show_on_map = models.BooleanField(default=False)
    time_zone = models.ForeignKey(TimeZone)

    def __str__(self):
        return "%s, %s, %s, %s" % (self.country, self.address_1,
self.region, self.area )

    def get_absolute_url(self):
        #return "/posts/%s/%s/" %
(self.date.strftime("%Y/%b/%d").lower(), self.slug)
        return "/locations/%i/" % self.id

    class Admin:
        ordering = ['country']
        list_display = ('country', 'address_1', 'address_2',
'region','area', 'postal_code', 'time_zone',)
        #list_filter =
('created_on','last_modified','enable_comments','pub_state',)
        


Thanks!
Nick Pavlica


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to