jrief / django-angular

Let AngularJS play well with Django
http://django-angular.awesto.com/
MIT License
1.23k stars 293 forks source link

Support added for multiple flat forms #204

Closed Nerade closed 8 years ago

Nerade commented 9 years ago

While working on an application with a view in which 4 forms are placed, I have noticed that the NgModelFormMixin grabs the data to each form by looking up a list which is placed as a value in the response data dict with a key equals to the prefix of the nested form. This only applies if the Form is nested to a parent form.

For my case the forms are bundled together on view layer. So there is just one dict with all form data and just seperated by the prefix in the key name.

This behaviour results in a 'NoneType has no method items()' error. To prevent this I have implemented a check if the data.get(self.prefix) is None. If so it will grab the data list by searching for all keys containing the prefix.

jrief commented 9 years ago

Sounds logical to me. Please give me some time, so that I can test this in my environment. Thanks for this pull request.

adrienbrunet commented 8 years ago

Good for me. We could merge this. An example or a demo would be really appreciated though. (The best would be an addition in the docs !) :wink:

@Nerade would you have the time for that?

adrienbrunet commented 8 years ago

Also, seing PR #210 we could use dict comprehension instead of dict(). Py2.7 is a standard almost everywhere and we do not maintain previous version of python.

adrienbrunet commented 8 years ago

Also in #210 , the check is done with if name.startswith(self.prefix + '.')} IMHO, it's a bit better than just self.prefix in name. What do you think?

Nerade commented 8 years ago

It is great to see my first contributed snippet to get into the project. I see your suggestion. In fact I am still fairly new to python concerning performance and code style issues.

I will further take a look into documentation when I'm home again.