hi maybe you can try this:
create a new class represent the traffic type( such as Carpool, and all
those traffic type ), add a class represent the traffic
category(roadtrip,commute... ).
the Rideshare class hava a reference to the traffic type, and the traffic
type have a reference to the traffic category class.

On 10/31/07, Alex Ezell <[EMAIL PROTECTED]> wrote:
>
>
> Hi,
> I am, as it will become painfully obvious, a new Django user. I am
> converting a PHP site to Django. Right now, the main DB table in the
> PHP site has around 100 columns and depending on the type of post
> being saved, it may leave around 60 of those empty.
>
> That's obviously an issue and I'd like to change it with this rewrite.
> Problem I am having is figuring out how to break up the columns in a
> way that makes sense, both from an app standpoint and from a Django
> model perspective.
>
> Right now, I have them in separated into 4 different tables, but even
> within those 4 different tables/classes, some of the fields will be
> unnecessary for certain types of posts.
>
> I know this is a lot of info, but my first question is, how can I make
> the field be required conditionally? That is, when I am creating a
> post of Type A, maybe the "title" field is not required, but if I am
> creating a post of Type B, maybe it is required. Should I move this
> required/not required out of the model and into the controller?
>
> For reference, below is one of the 4 classes I am defining. In this
> instance only one of roadtrip_type, airport_type, commute_type, or
> drive_type is required depending on which type of "Rideshare" you are
> saving.
>
> I've read through the docs on Models and about the DB-API but I am
> still having trouble solving this stuff. Thanks in advance for your
> time and thoughts.
>
> /alex
>
> class Rideshare(models.Model):
>    title = models.CharField(max_length=150)
>    slug = models.SlugField(prepopulate_from=("title",),max_length=30)
>    from_city = models.CharField(max_length=150)
>    from_state = models.USStateField()
>    from_zip = models.IntegerField()
>    to_city = models.CharField(max_length=150)
>    to_state = models.USStateField()
>    to_zip = models.IntegerField()
>    depart_date = models.DateField()
>    pickup_time = models.TimeField()
>    ROADTRIP_TYPE_CHOICES = (
>        ('PC', 'Personal Car'),
>        ('RC', 'Rental Car'),
>        ('VA', 'Van'),
>        ('RV', 'RV'),
>        ('BU', 'Bus'),
>    )
>    roadtrip_type = models.CharField(max_length=2,
> choices=ROADTRIP_TYPE_CHOICES)
>    COMMUTE_TYPE_CHOICES = (
>        ('CP', 'Carpool'),
>        ('VP', 'Vanpool'),
>    )
>    commute_type = models.CharField(max_length=2,
> choices=COMMUTE_TYPE_CHOICES)
>    AIRPORT_TYPE_CHOICES = (
>        ('TS', 'Taxishare'),
>        ('SS', 'Shuttle Service'),
>        ('TC', 'Town Car/Limo'),
>        ('PC', 'Personal Car'),
>        ('RC', 'Rental Car'),
>    )
>    airport_type = models.CharField(max_length=2,
> choices=AIRPORT_TYPE_CHOICES)
>    "choose below","personal driver","messenger","errands","local delivery"
>    DRIVE_TYPE_CHOICES = (
>        ('PD', 'Personal Driver'),
>        ('ME', 'Messenger'),
>        ('ER', 'Errands'),
>        ('LD', 'Local Delivery'),
>    )
>    drive_type = models.CharField(max_length=2, choices=DRIVE_TYPE_CHOICES)
>    GENDER_CHOICES = (
>        ('O', 'Male or Female'),
>        ('M', 'Male'),
>        ('F', 'Female'),
>    )
>    passenger_gender = models.CharField(max_length=1,
> choices=GENDER_CHOICES)
>    SMOKING_CHOICES = (
>        ('O', 'Smoker or Non-Smoker'),
>        ('N', 'Non-Smoker'),
>        ('S', 'Smoker'),
>    )
>    passenger_smoking = models.CharField(max_length=1,
> choices=SMOKING_CHOICES)
>    AGE_CHOICES = (
>        ('0', 'Any Age'),
>        ('1', '18-23'),
>        ('2', '24-29'),
>        ('3', '30-34'),
>        ('4', '35-39'),
>        ('5', '40-45'),
>        ('6', '46-50'),
>        ('7', '50-59'),
>        ('8', '60+'),
>    )
>    passenger_age = models.CharField(max_length=1, choices=AGE_CHOICES)
>    DAYS_CHOICES = (
>        ('MF', 'Monday-Friday'),
>        ('MO', 'Monday'),
>        ('TU', 'Tuesday'),
>        ('WE', 'Wednesday'),
>        ('TH', 'Thursday'),
>        ('FR', 'Friday'),
>        ('SA', 'Saturday'),
>        ('SU', 'Sunday'),
>    )
>    days_of_week = models.CharField(max_length=2, choices=DAYS_CHOICES)
>    HOURS_CHOICES = (
>        ('24', '24 Hours'),
>        ('EM', 'Early Morning'),
>        ('DT', 'Daytime'),
>        ('AN', 'Afternoon'),
>        ('EV', 'Evening'),
>        ('LN', 'Late Night'),
>    )
>    hours_available = models.CharField(max_length=2, choices=HOURS_CHOICES)
>    SEATS_CHOICES = (
>        ('1', '1'),
>        ('2', '2'),
>        ('3', '3'),
>        ('4', '4'),
>        ('+', '4 or more'),
>    )
>    seats_available = models.CharField(max_length=1, choices=SEATS_CHOICES)
>    leave_by = models.CharField(max_length=20)
>    return_at = models.CharField(max_length=20)
>    airport_name = models.CharField(max_length=100)
>    rate = models.CharField(max_length=20)
>    rate_per = models.CharField(max_length=10)
>    created = models.DateTimeField(auto_now_add=True)
>    modified = models.DateTimeField(auto_now=True)
>    fromLat = models.CharField(max_length=20)
>    fromLon = models.CharField(max_length=20)
>    toLat = models.CharField(max_length=20)
>    toLon = models.CharField(max_length=20)
>    notes = models.TextField()
>    VIEW_LEVEL_CHOICES = (
>        ('PU', 'Public'),
>        ('GR', 'Group Only'),
>    )
>    view_level = models.CharField(max_length=2, choices=VIEW_LEVEL_CHOICES)
>    class Admin:
>        # Admin options go here
>        pass
>
> >
>

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

Reply via email to