2

I want to add, some fields depending on others. I have city and country model. I can include country as foreign key in city model. And then if I will add both city and country in another model ( say content) then will it be just like dependent selectboxes? like cities will be shown based on selected country via ajax? If not then what is correct way? and also is there a way to add city on the spot while adding main content data if city is not already on list?

So are above possible by using django admin or is it that django don't give? If not then how can it be done in django autogenerated admin?

BNL
  • 7,085
  • 4
  • 27
  • 32
Hafiz
  • 4,187
  • 12
  • 58
  • 111

2 Answers2

3

You can do exactly what you ask using django-smart-selects

Hope that helps...

danodonovan
  • 19,636
  • 10
  • 70
  • 78
1

I can include country as foreign key in city model

This seems like a good idea.

And then if I will add both city and country in another model ( say content) then will it be just like dependent selectboxes? like cities will be shown based on selected country via ajax?

No, it will not get filtered automatically, you will need to write that code yourself. Both in admin and on frontend.

and also is there a way to add city on the spot while adding main content data if city is not already on list?

You will get this in the admin area.

Go ahead and start doing it, and when you run into specific problems, post them here if you can't solve it. Also read the Django docs, it is pretty elaborate on the topic of models.

Ska
  • 6,658
  • 14
  • 53
  • 74
  • so what I am looking for is not possible in django admin itself? – Hafiz Nov 14 '11 at 00:26
  • and can't be last thing do by using `inlines = [CityInline]` ? – Hafiz Nov 14 '11 at 00:39
  • 1
    Inlines can help in this case, I'm not particularly sure what you want to do. I suggest that you go ahead and start doing it and the answers will present themselves. Once you come to particular point post the code and people will help you. There's a lot of docs around how to overcome this. – Ska Nov 14 '11 at 01:01
  • admin of django-1.3 do this last thing by default without any need of inlines, it have a plus sign with any drop down and admin can add any new object if it is not already in list by clicking that plus icon. – Hafiz Nov 14 '11 at 08:58
  • Yes, this is what I answered for your third question. To quote: "You will get this in the admin area." – Ska Nov 14 '11 at 15:14