Comments (6)
I think its happening 'cause the .each() jquery function isnt correct
My View Class
class KeyResultEditView(BSModalUpdateView):
model = CompanyKeyResult
template_name = 'modals/edit_keyresult.html'
form_class = CompanyKeyResultForm
success_message = 'Resultado chave alterado com sucesso.'
success_url = reverse_lazy('okr_company')
def dispatch(self, request, *args, **kwargs):
self.key_result = get_object_or_404(CompanyKeyResult, pk=kwargs['pk'])
ProgressHistory.objects.create(history_company_key_result=self.key_result, date=self.key_result.date, percent=self.key_result.percent)
return super().dispatch(request, *args, **kwargs)
Url
path('modals/edit-kr/<int:pk>', views.KeyResultEditView.as_view(), name='edit_key_result'),
Js
$(".edit-kr").each(function(){ $(this).modalForm({formURL: $(this).data('id')}); });
from django-bootstrap-modal-forms.
@bryannatali I would say that each
function is not a problem. It's identical to the docs. What do you mean when saying that the form is submitted 3 times? It normal that it's submitted 2 times. Check #14.
from django-bootstrap-modal-forms.
okay, thank you for quick response.
When I submit the modal this ProgressHistory.objects.create(history_company_key_result=self.key_result, date=self.key_result.date, percent=self.key_result.percent)
happens three times. So the model is created three times on db.
from django-bootstrap-modal-forms.
@bryannatali Ok, now I see. You defined a creation of another object inside of a dispatch
method. Although it works and creates an object, my opinion is that you shouldn't use Django in this way. So you need to figure out how to move this code out of dispatch. When you POST the form dispatch
is called. In case of my package two POSTs result in two dispatch calls, so this explains why two objects are created however I don't know where the third comes from. So reconsider your design and definitely don't abuse dispatch
method.
from django-bootstrap-modal-forms.
Oh, thank you again!
Based on what you said I changed my ViewClass to:
class KeyResultEditView(BSModalUpdateView):
model = CompanyKeyResult
template_name = 'modals/edit_keyresult.html'
form_class = CompanyKeyResultForm
success_message = 'Resultado chave alterado com sucesso.'
success_url = reverse_lazy('okr_company')
def dispatch(self, request, *args, **kwargs):
self.key_result = get_object_or_404(CompanyKeyResult, pk=kwargs['pk'])
return super().dispatch(request, *args, **kwargs)
def form_valid(self, form):
try:
ProgressHistory.objects.get(date=self.key_result.date, percent=self.key_result.percent)
except ProgressHistory.DoesNotExist:
ProgressHistory.objects.create(history_company_key_result=self.key_result, date=self.key_result.date, percent=self.key_result.percent)
return super().form_valid(form)
and it works!
from django-bootstrap-modal-forms.
@bryannatali That's great. I'm glad you made it. Star 70 highly appreciated ;)
from django-bootstrap-modal-forms.
Related Issues (20)
- missing "database" folder
- Allow to send extra parameters in the POST request.
- Multiple submit buttons in modal
- Maintenance of the project HOT 9
- Automate JS Minify Process
- How to make a nested modal
- Undesired GET request when using a BSModalCreateView HOT 4
- Incorrect errorClass in documentation HOT 1
- Generic views don't respond to get_success_url() since version 3.0.0 HOT 5
- Delete view success message is shown although object not deleted HOT 1
- form validation object already exist error does not shown in modal after modal form submissin with crispy form within modal HOT 3
- Django Internal server error - widget_tweaks failed to parse render_field HOT 1
- Checkbox does not render correctly. HOT 3
- btnSubmit fails detection after html minification
- Double post when submitting modal form HOT 5
- Restrict users from directly accessing the form url HOT 1
- How to remove Click listener HOT 1
- Open a new modal with the current modal form's results
- Event listeners disappear after the form is invalid. HOT 1
- FormValidationMixin shadows setting of self.object (defined in BaseCreateView)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-bootstrap-modal-forms.