sql
html
iphone
python
database
android
ruby-on-rails
regex
objective-c
multithreading
eclipse
flash
html5
json
algorithm
oracle
php5
api
jsp
postgresql
In the given example of for country = ChainedForeignKey() field, the chained_field="continent" refers to the "continent" field in Location class. The chained_model_field="continent" refers to a "continent" field inside the Country model (which is not shown in the example).
That is the way I interpreted it dragonx. But I am obviously missing something.
I am thinking the other classes look like this
class Continent(models.Model): continent = models.CharField(max_length=45) def __unicode__(self): return self.continent class Country(models.Model): continent = models.ForeignKey(Continent) country = models.CharField(max_length=45) def __unicode__(self): return self.county
with "continent" in the Country class being an integer field that corresponds to the ID field of the Continent class (ForeignKey/field) upon which the join is made. Is this the way you see it?
You should insert this in the urls.py:
url(r'^chaining/', include('smart_selects.urls')),
This is what I did and worked:
#================================= #models.py from smart_selects.db_fields import ChainedForeignKey class Continent(models.Model): continent = models.CharField(max_length = 45) def __unicode__(self): return unicode(self.continent) class Country(models.Model): continent = models.ForeignKey(Continent) country = models.CharField(max_length = 45) def __unicode__(self): return unicode(self.country) class Area(models.Model): country = models.ForeignKey(Country) area = models.CharField(max_length = 45) def __unicode__(self): return unicode(self.area) class Location(models.Model): continent = models.ForeignKey(Continent) country = ChainedForeignKey ( Country, chained_field = "continent", chained_model_field = "continent", show_all = False, auto_choose = True ) area = ChainedForeignKey(Area, chained_field = "country", chained_model_field = "country") city = models.CharField(max_length = 50) street = models.CharField(max_length = 100) #================================= #admin.py from yourapp.models import Continent from yourapp.models import Country from yourapp.models import Area from yourapp.models import Location class ContinentAdmin(admin.ModelAdmin): pass class CountryAdmin(admin.ModelAdmin): pass class AreaAdmin(admin.ModelAdmin): pass class LocationAdmin(admin.ModelAdmin): pass admin.site.register(Continent, ContinentAdmin) admin.site.register(Country, CountryAdmin) admin.site.register(Area, AreaAdmin) admin.site.register(Location, LocationAdmin)