On Wed, 2006-06-14 at 22:15 -0700, [EMAIL PROTECTED] wrote:
> All,
>   I have been trying to create a model for a project that I'm starting
> with the trunk version of Django(revision 3129 or newer).  In the
> following example I'm trying to create a model that allows the site
> administrator(s) to create locations based on Country, State, and City
> then associate them with a Job.  In the Admin I can create the Country,
> State, and City records/objects with the appropriate relationships.
> However when I relate them with the Job class the Admin doesn't
> restrict the selections with there respective constraints.


> For
> example, I can create a new job object with the following information:
> Country = US, State = Kansas, City = Chicago despite the fact that I
> created that object/record with the following relationships: Country =
> US, State = Kansas, City = Lawrence. 

Your model is not really set up to provide this type of data integrity
(well, firstly your model is not set up to actually run... you need to
replace "Region" with "State", or vice versa, in you example).

Instead of duplicating the region and country fields in the Job model, I
would keep them purely as a property of the City model. A City instance
already carries around with it the information about which region and
country it belongs to.

I would remove "region" and "country" from the Job model and change the
__str__ method on the City model to return something that includes the
region and country (after all, a city name is not a unique identifier,
but combining it with state + country, where appropriate, helps narrow
it down). You can still access region and country easily enough via
job.city.state and job.city.country. 

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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