Code Monkey home page Code Monkey logo

cb_dj_dependent_dropdown's People

Contributors

akjasim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cb_dj_dependent_dropdown's Issues

Fix to avoid NoneType error.

Some people may encounter the error of 'NoneType' object has no attribute 'city_set' if you implement this to a profile system or any other similar model. My way around to fix it was :

   if 'country' in self.data:
        try:
            country_id = int(self.data.get('country'))
            self.fields['city'].queryset = City.objects.filter(country_id=country_id).order_by('name')
        except (ValueError, TypeError):
            pass  # invalid input from the client; ignore and fallback to empty City queryset
    elif self.instance.pk:
          try:
              self.fields['city'].queryset = self.instance.country.city_set.order_by('name')
          else:
              pass

Regarding the Chain Dropdown Menu

Is there a better way to do that because if you look at the steps and start imagining a bigger project, the coding style wouldn't be pleasing at all.
for one dropdown menu, you had to do a lot of things, imagine if you have 10s of them.
please if there is a better way to deal with it, share.

Thanks a lot for the wonderful lesson, but it didn't work with the update.
if I want to update, the chain dropdown shows all the cities regardless of the country, even though in the elif self.data.instance.pk is mentioned, and I think this is related to update. I could be wrong, but it didn't work with update in my case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.