Re: Enforcing relationships in the Admin

2006-06-19 Thread [EMAIL PROTECTED]

Malcolm Tredinnick wrote:
> You're not really providing enough information that I can make concrete
> suggestions here. How would the "focus" of the more restricted selection
> set be determined? The standard options are...
>
> (1) If it's something you can work out from other, previously filled in
> fields on the page, then you could use the 'js' option in the Admin
> class to add some custom Javascript. See [1] for some useful posts about
> this possibility.
>
> (2) If you want something more interactive and customised, such as
> clicking on a map or specifying the general area prior to entering any
> details, then you can write your own form for input. The admin interface
> provides a reasonably generic input form that works for many cases up to
> a point. But once you want custom input, particularly for slightly
> unwieldy data constructs or sizes, it often pays to just knock up a
> quick custom input form and do it yourself.
>
>
> [1] http://groups.google.com/group/django-users/search?q=Admin+js
> +option=0=d&
>
> Hope this provides you with some food for thought.

Hi Malcolm,
  I was trying to achieve option one for this project.  Essentially, I
would like to provide the user with the ability to assign a specific
location for each job by selecting a Country, State, & City.  In my
original model I was trying to manipulate the dynamically generated
Admin interface with my model so that it would allow me to filter the
options presented to the user based on the relationships in the model.
After implementing your initial suggestions I was able to create a
situation where the user could easily select a City that had a Country
and State based on there relationships in the model.  The down side of
this approach is that when I add all of the possible locations, the
user would have a list with thousands of options.  This wouldn't be
very user friendly, so I need to be able to narrow down the
possibilities as follows:

  Country: (A drop down list of countries)
 - United States
 - Canada
 - Etc.

  State: (A drop down list of states based on the previous country
selection)
 + United Sates
- Would provide: Wyoming, Colorado, Kansas, Etc.

 + Canada
- Would provide: Alberta, British Columbia, Manitoba,
Etc.

  City: (A drop down list of cities based on the previous Country and
State selections)
 + Wyoming
   - Would provide: Cheyenne, Laramie, Casper, Etc.

 + Colorado
- Would provide: Denver, Ft. Collins, Greeley, Etc.

  + Kansas
- Would provide: Lawrence, Kansas City, Salina, Etc.

  + Alberta
- Would provide: Beaumont, Bonnyville, Provost, Etc.

  + And so on...


  At this point the 'js' option in the Admin is the obvious choice for
this problem.  Here is what I currently have in mind:
- Revert my job model so that it has a column for Country, State, &
City.
- Utilized the 'js' option in the Admin with the appropriate 'js'
script to provide the functionality in my example above.

Many Thanks!
--Nick


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



Re: Enforcing relationships in the Admin

2006-06-15 Thread Malcolm Tredinnick

On Thu, 2006-06-15 at 09:07 -0700, [EMAIL PROTECTED] wrote:
> All,
>   I have modified the original example model based on your suggestions,
> and I feel like I'm another step closer to what I'm trying to
> accomplish.  Thanks for the suggestions!  However, one issue that I
> have with the current solution is scalability.  Because there will be
> thousands of possible job locations,  when a site manager creates a Job
> based on the current solution they would be presented with thousands of
> possible cities when they select the city drop down box.  This would
> make it difficult for the site manager to associate the Job they are
> creating with a location.  How would I modify the current model example
> v0.2  to allow a more focused selection of locations in the Admin?

You're not really providing enough information that I can make concrete
suggestions here. How would the "focus" of the more restricted selection
set be determined? The standard options are...

(1) If it's something you can work out from other, previously filled in
fields on the page, then you could use the 'js' option in the Admin
class to add some custom Javascript. See [1] for some useful posts about
this possibility.

(2) If you want something more interactive and customised, such as
clicking on a map or specifying the general area prior to entering any
details, then you can write your own form for input. The admin interface
provides a reasonably generic input form that works for many cases up to
a point. But once you want custom input, particularly for slightly
unwieldy data constructs or sizes, it often pays to just knock up a
quick custom input form and do it yourself.


[1] http://groups.google.com/group/django-users/search?q=Admin+js
+option=0=d&

Hope this provides you with some food for thought.

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



Re: Enforcing relationships in the Admin

2006-06-14 Thread Andy Todd

On 6/15/06, [EMAIL PROTECTED] <[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.  How can I limit the choices in
> the Admin interface for Country, State, and City with there appropriate
> relationships when I create Job objects?  I have spent quite a bit of
> time looking/Googleing for a clear example of how to do this, but
> haven't had any luck.  Could you please look over this example model
> and modify it so that it works as desired, and post it back to the
> list.  It would probably be a good addition to the documentation as
> well, so I will submit it as a documentation example, or add it to the
> cookbook once things are hashed out.
>
> Thanks For Your Help!
> -Nick
>
> Example Model:
> ##
>
> from django.db import models
>
> class Country(models.Model):
> name = models.CharField(maxlength=100, core=True, unique=True)
>
> def __str__(self):
> return (self.name)
>
> class Admin:
> pass
>
> class State(models.Model):
> country = models.ForeignKey(Country)
> name = models.CharField(maxlength=100, unique=True, core=True)
>
> def __str__(self):
> return (self.name)
>
> class Admin:
> pass
>
> class City(models.Model):
> region = models.ForeignKey(Region)
> name = models.CharField(maxlength=100, unique=True, core=True)
>
> def __str__(self):
> return (self.name)
>
> class Admin:
> pass
>
> class Job(models.Model):
> created_on = models.DateTimeField(auto_now_add=True)
> country = models.ForeignKey(Country)
> region = models.ForeignKey(State)
> area = models.ForeignKey(City)
> title = models.CharField(maxlength=100)
> summary = models.CharField(maxlength=500)
> body = models.TextField(blank=True, help_text="Optional")
> image = models.URLField(verify_exists=True, blank=True,
> help_text="Optional")
> file = models.URLField(verify_exists=True, blank=True,
> help_text="Optional" )
>
>
> def __str__(self):
> return (self.title)
>
> class Admin:
> pass
>
>
> >
>

Change your model to only link from Job to City. Then the State and
Country values can be inferred from traversing through your model.

Because you've got independent links to Country, State and City they
don't need to be dependent.

Oh, and you should probably standardise on using either Region or
State, at the moment you appear to be using the terms interchangeably
and it makes your model slightly confusing.

Regards,
Andy
-- 
>From the desk of Andrew J Todd esq

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



Re: Enforcing relationships in the Admin

2006-06-14 Thread Malcolm Tredinnick

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