-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Passing values to Detailview of Popup #5
Comments
I will try find solution, please be patient. |
Can you prepare full not working example.
I can add a new functionality but I would like to have a good example. |
This a non working example:
*I have two models in models.py*
Class AP(models.Model):
name=models.CharField(max_length=200)
APid=models.CharField(max_length=200)
description1= models.CharField(max_length=200)
description2= models.CharField(max_length=200)
description3= models.CharField(max_length=200)
Class APReview(models.Model):
atPat=models.ForeignKey(AP)
rating = models.IntegerField(choices=RATING_CHOICES)
selectionReason=models.CharField(max_length=200)
*In my forms.py, I have -*
class APReview(ModelForm):
class Meta:
model=APReview
fields=['rating', 'selectionReason', ]
selectionReason=PopupViewField(
view_class=SelectionReasonPopUpViews,
popup_dialog_title="Please select a reason for",
required=True,
)
def __init__(self, *args, **kwargs):
super(APReviewForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
*In my popups.py, I have - *
class SelectionReasonPopUpViews(DetailView):
template_name = 'popups/selectionReason.html'
model = AttackPattern
context_object_name = 'attackpattern'
def get(self, request, *args, **kwargs):
return super(SelectionReasonPopUpViews, self).get(request, *args,
**kwargs)
def get_object(self):
*#I would like to pass the APiD of AP to myID*
*#This should just get a specific AP based on the myID value*
obj = get_object_or_404(AP, APid=myID)
return obj
*In my popups/selectionReason.html file, I have - *
<ul>
<li data-popup-view-value="Description 1"> {{AP.description1}} </li>
<li data-popup-view-value="Description 2"> {{AP.description2}} </li>
<li data-popup-view-value="Description 3"> {{AP.description3}} </li>
</ul>
*In my views.py, I have - *
class AuthorCreateView(CreateView):
form_class = AuthorForm
template_name = 'APReview_new.html'
success_url = 'success'
*In my APReview_new.html file, I have - *
<form method="POST" enctype="multipart/form-data">
{% for hidden_field in form.hidden_fields %}
{% endfor %}
{% csrf_token %}
{{ form.management_form }}
{{ form.non_form_errors }}
{{form}}
<input class="btn" type="submit" value="Update" />
</form>
Overall, I would like the SelectionReasonPopUpViews to display the
descriptions of an AP when the selectionReason form field is clicked from
the APReview_new.html file.
…On Fri, Sep 21, 2018 at 1:54 AM K2 ***@***.***> wrote:
Can you prepare full not working example.
I do not quite understand how you would like to pass a PK from an object
to DetailView. Currently, it is not possible to forward PK in the url,
because the views are regitraed in a simple way
` url (r '^ (? P <view_class_name> \ w +) / $', GetPopupView.as_view (),
name = "get_popup_view"), `
I can add a new functionality but I would like to have a good example.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALC_jCNULAfgwkonPNsXm1tspNBTCFnLks5udH8MgaJpZM4VuHWC>
.
|
Hi. You can test your code if you run demo and hit to url : Example:
|
@ImanoWilliams Can you see my new branch issuse_5 |
K2,
I apologize for not reply to you sooner. Yes, I can see issue 5 branch. I
will copy the modified code base to my existing source code.
Best regards,
IWill
…On Mon, Oct 1, 2018 at 4:31 AM K2 ***@***.***> wrote:
@ImanoWilliams <https://github.com/ImanoWilliams> Can you see my new
branch *issuse_5*
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALC_jBAJeoGNI0dkX7yctwPV7BsCpNDMks5ugdL9gaJpZM4VuHWC>
.
|
Thanks for info.
|
I got it to work.
class APReviewForm(forms.ModelForm):
class Meta:
model=APReview
fields=['rating', 'selectionReason', ]
def __init__(self, *args, **kwargs):
super(APReviewForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.fields['selectionReason']=PopupViewField(
view_class=SelectionReasonPopUpViews,
popup_dialog_title="Please select a reason for",
callback_data={'my_id':*'APid_1'*, 'other_param': 'xxx'},
required=True,
)
I changed 'APiD_1' to *self.instance.attackPattern*
Where *attackPattern* is one of the fields in APReview model
Thank you for your assistance.
…On Mon, Oct 1, 2018 at 10:17 AM K2 ***@***.***> wrote:
Thanks for info.
I will wait for response.
K2, I apologize for not reply to you sooner. Yes, I can see issue 5
branch. I will copy the modified code base to my existing source code. Best
regards, IWill
… <#m_-6969385755930851696_>
On Mon, Oct 1, 2018 at 4:31 AM K2 ***@***.***> wrote: @ImanoWilliams
<https://github.com/ImanoWilliams> https://github.com/ImanoWilliams Can
you see my new branch *issuse_5* — You are receiving this because you
were mentioned. Reply to this email directly, view it on GitHub <#5
(comment)
<#5 (comment)>>,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALC_jBAJeoGNI0dkX7yctwPV7BsCpNDMks5ugdL9gaJpZM4VuHWC
.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALC_jF83jSC9oyMIpal96C9-u36jTf93ks5ugiQKgaJpZM4VuHWC>
.
|
Its Great. |
Release 0.4.0 |
Thank you.
…On Thu, Oct 4, 2018 at 1:25 PM K2 ***@***.***> wrote:
Release 0.4.0
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALC_jO43j7hRWmxSRAaJAJuEleupBoCxks5uhkR7gaJpZM4VuHWC>
.
|
@djk2 I want to make a detailview popupview like so. When the user clicks on the selectionReason where the popupfield is placed, I want to pass a primary key from the AttackPatternForm to detail view of the popupview. I will then call the attackpattern values in the template file.
I basically want to get a value from the template file where the AttackPatternForm is and pass it to the
popupview that inherits from Detail view. See code below. It is quite similar to your CountryPopupView, but the user would not search since the query filter will be passed in from the template that renders AttackPatternForm.
My issue is how to pass the value from the form and then use it to query in the detailview of the popupfield view.
forms.py
popups.py
template: 'popups/selectionReason.html
The text was updated successfully, but these errors were encountered: