Re: How to update django MultiModelForm? Please HELP

2018-06-25 Thread Django Lover
I think This is very easy anyone 1 Year experienced guy can answer it.

On Monday, June 25, 2018 at 6:51:14 PM UTC+5:30, Sunil Kothiyal wrote:
>
> Hello All,
>
>  I had created multiModelForm in Django, I can view, and save data, I 
> don't know how to Update data into the database. I want if user id exists 
> in database then update else insert.exist in the database then update else 
> insert.
>
> This Code is working for me but I don't know how to update existing data?
>
> # forms.py
> from django import forms
> from authtools.forms import UserCreationForm
> from betterforms.multiform import MultiModelForm
> from .models import UserProfile
>
> class UserProfileForm(forms.ModelForm):
> class Meta:
> fields = ('favorite_color',)
>
> class UserCreationMultiForm(MultiModelForm):
> form_classes = {
> 'user': UserCreationForm,
> 'profile': UserProfileForm,
> }
>
> # views.py
> from django.views.generic import CreateView
> from django.core.urlresolvers import reverse_lazy
> from django.shortcuts import redirect
> from .forms import UserCreationMultiForm
>
> class UserSignupView(CreateView):
> form_class = UserCreationMultiForm
> success_url = reverse_lazy('home')
>
> def form_valid(self, form):
> # Save the user first, because the profile needs a user before it
> # can be saved.
> user = form['user'].save()
> profile = form['profile'].save(commit=False)
> profile.user = user
> profile.save()
> return redirect(self.get_success_url())
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/94c3bcc9-3f89-47da-869f-de031f77f5d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to create dynamic form field? Django 2.0

2018-07-19 Thread Django Lover


Here is the image of the form what is need when user click on "Add New Tax 
" two input (Tax name and Value ) should generate dynamically and with all 
field of the form.


 


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d323c889-020f-46a0-9e14-b8bb26c9abdb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to create dynamic form field? Django 2.0

2018-07-19 Thread Django Lover
This is hard for me understand can you please give some code. I am new in 
Django. PLEASE HELP ME

On Thursday, July 19, 2018 at 7:26:29 PM UTC+5:30, C. Kirby wrote:
>
> https://docs.djangoproject.com/en/2.0/topics/forms/formsets/ to allow for 
> multiple instances of the same form type. Then you will need some 
> javascript to handle showing additional instances of the form when the 
> button is clicked
>
> On Thursday, July 19, 2018 at 9:29:51 AM UTC-4, Django Lover wrote:
>>
>> Here is the image of the form what is need when user click on "Add New 
>> Tax " two input (Tax name and Value ) should generate dynamically and with 
>> all field of the form.
>>
>> <https://lh3.googleusercontent.com/-WL_9Np4MV0M/W1CRf9tI_RI/AP0/0KAi2WX8UfMTDnO7YsW28dzE-r-YTiSOwCLcBGAs/s1600/django%2BDynamic.png>
>>
>> <https://lh3.googleusercontent.com/-WL_9Np4MV0M/W1CRf9tI_RI/AP0/0KAi2WX8UfMTDnO7YsW28dzE-r-YTiSOwCLcBGAs/s1600/django%2BDynamic.png>
>>  
>> <https://lh3.googleusercontent.com/-WL_9Np4MV0M/W1CRf9tI_RI/AP0/0KAi2WX8UfMTDnO7YsW28dzE-r-YTiSOwCLcBGAs/s1600/django%2BDynamic.png>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/734e4c1c-ec9c-4627-93c8-5d2e692c9447%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to create dynamic form field? Django 2.0

2018-07-19 Thread Django Lover
@Melvyn Sopacua Can you please give me simple solution of this problem?

On Friday, July 20, 2018 at 11:15:06 AM UTC+5:30, Melvyn Sopacua wrote:
>
> On donderdag 19 juli 2018 16:18:07 CEST Django Lover wrote: 
> > This is hard for me understand can you please give some code. I am new 
> in 
> > Django. PLEASE HELP ME 
>
> If you're new to Django don't try to do this and learn more about Django 
> first. 
> You don't have the knowledge to break down your problem into the right 
> components, which for a Django developer up to the task would be very 
> simple 
> (as shown by the replies). 
> Walk before your run. 
> -- 
> Melvyn Sopacua 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/add2bc6a-9684-4930-b1ac-3c51c1209d8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


I am not able to install mysql for python.

2018-09-06 Thread Django Lover


*I am getting following error when i am running pip install mysql-python
 Comand . Please help??*



[image: asd.png] 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bacaac61-3f35-4f2b-bf01-058fcd5a8eb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Not able to install mysql for pyhton.

2018-09-06 Thread Django Lover
*I am getting following error when i am running pip install 
mysql-python Comand . Please help??*



[image: asd.png] 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/422f7d21-3414-42d6-a51f-ade57bdc3b4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to save multiple model form in one template?

2018-09-07 Thread Django Lover

I have one page, which I have to show three model form and three 
different submit button for each.

My question is how I can save these three form individually?

FOLLOWING IS CODE:-

**form.py**


class UserTaxesMultiForm(MultiModelForm):
   form_classes = {
   'user_tax_form': MyForm,
   'user_discount_form': DiscountForm,
   'user_shiping_form': ShipmentForm,
   }

*Note- myForm, DiscountForm, ShipmentForm are model forms. like following-*

class MyForm(forms.ModelForm):
   prefix = 'tax'
   class Meta:
   model = StUserTaxDetails
   fields = ('tax_name', 'tax_rate')
 
   tax_name = forms.CharField(max_length=10,
widget=forms.TextInput(),
required=True, label="tax name")

tax_rate = forms.FloatField(required=True,  label="tax rate")


error_messages  = {
   'required': _('fields are required.'),
   }

def clean_title(self):
   return self.cleaned_data['tax_name']

def clean(self):
   tax_name = self.cleaned_data.get('tax_name')
   tax_rate = self.cleaned_data.get('tax_rate')

if not tax_name and not tax_rate:
   raise forms.ValidationError(
   self.error_messages['required'],
   code='required',
   )
   return self.cleaned_data

**view.py**
class AddTaxView(LoginRequiredMixin, CreateView):
   template_name = 'invoices/add_tax.html'
   form_class = UserTaxesMultiForm
   success_url = '/add/tax/'

   *{WHAT IS THE CODE HERE FOR THE POST METHOD TO SAVE DATA ACORDING 
DIFFRENT FORM SUBMIT} *




**HTML**




{% form.user_tax_form%}





{% form.user_discount_form%}





{% form.user_shiping_form%}




PLEASE HELP

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/45a017a3-9633-426f-81e1-b261189e714a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to publish Django 2 Application using WHM/Cpanel?

2018-09-10 Thread Django Lover
Dear Django Community!!

I have a dedicated centos server with root access with WHM, I am new to 
python. Please, Can you give me information about how I can launch my 
Django website??

But the condition is-

1- Server have 4 user account(i.e. A, B,C,D).

2- I want to install Django only for user D. 

3- Other users should not feel any trouble. they are running PHP, Wordpress.

4- If any trick without putty / SSH 

Thank you in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0dc0e11c-f46a-47b0-a2fe-6ad5521b9459%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to get multi form initial data?

2018-09-11 Thread Django Lover
I have the view like this-

The form is working good but i issue is not able to get from initial data. 
PLEASE HELP

**formview.py**


class AddProfile(LoginRequiredMixin, CreateView):

template_name = 'users/add_user_details.html'
   form_class = {
   'contactInformation': ContactInformationForm,
   'additionalInfomation': AdditionalInfomationForm,
   'userDetailsForm': UserDetailsForm, 
'userBusinessDetailsForm':UserBusinessDetailsForm,
   }
   success_url = '/dashboard/'

*//HERE IS CODE TO GET INITIAL DATA BUT NOT ABLE TO GET IT.*

def get_initial(self):
   if self.request.GET:
   initial = super(AddProfile, self).get_initial()

user = self.request.user
   initial['first_name'] = user.first_name
   initial['last_name'] = user.last_name
   initial['email'] = user.email

return initial

def form_valid(self, form):
user = self.request.user

# UserDetailsForm = form['userDetailsForm'].save(commit=False)
   userBusinessDetailsForm = form['userBusinessDetailsForm'].save(
   commit=False)
   contactInformation = form['contactInformation'].save(commit=False)
   additionalInfomation = form['additionalInfomation'].save(commit=False
)

is_business = self.request.POST.get('business_selection') 
status = False
   if is_business:
   status = True
   else:
   status = False
   
   user.first_name = form['userDetailsForm'].cleaned_data.get(
'first_name')
   user.last_name = form['userDetailsForm'].cleaned_data.get('last_name'
)
   user.email = form['userDetailsForm'].cleaned_data.get('email')
   user.save()

# UserDetailsForm.user = user
   # UserDetailsForm.save()

contactInformation.user = user
   contactInformation.save()

contactInformation.business_or_individual = status
   contactInformation.save()

additionalInfomation.user = user
   additionalInfomation.save()

userBusinessDetailsForm.user = user
   userBusinessDetailsForm.save()

messages.add_message(self.request, messages.SUCCESS, _('Profile 
details has been successfully updated.'))
   return super(AddProfile, self).form_valid(form)  



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4cef2a2c-52d2-4611-8ca6-af7473adf78c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to insert setting when user creating?

2018-09-17 Thread Django Lover
Dear Django community, I am stuck in a logical condition where I need your 
help. 

1- I am registering a user using default *Django auth user and 
social_django library, *I need when user registering it should submit 
default model value in one more table.  

Like-
model - user(default)
model - userprofile (when user creates insert id and default value related 
settings.)

[image: Untitled.png]

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cb0353ef-6488-40cc-a69f-da1567e635ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to update if user exist instead of create?

2018-09-18 Thread Django Lover
How i can update model when Key exist else create a new one??
 

My code is-
 
**Form.py**

class UserSettingForm(forms.ModelForm):
 class Meta:
   model = StUserSetting
   fields = ( 'default_language', 'prim_currency', 'number_format', 
'decimal_format',
'date_format', 'time_format', 'currency_format', 
'currency_position', 'financial_year_start', 
 'week_start', 'estimate_default_tab', 'invoice_default_tab',)

**View.py**


class CreateUpadateUserSetting(LoginRequiredMixin, FormView):
 template_name = 'settings/user_settings.html'
 form_class = UserSettingForm
 success_url = '/user/setting/preference/'


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/177de87e-ec35-4cb2-a99d-16688dcdda7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to update if user exist instead of create?

2018-09-18 Thread Django Lover
Thanks, Larry for replying. I want to say I am new in Django and I 
don't know how to use in class-based view, Can you help me to 
integrate with CBV?

On Tuesday, September 18, 2018 at 5:57:28 PM UTC+5:30, larry@gmail.com 
wrote:
>
> On Tue, Sep 18, 2018 at 8:13 AM, Django Lover  > wrote: 
> > How i can update model when Key exist else create a new one?? 
> > 
> > 
> > My code is- 
> > 
> > **Form.py** 
> > 
> > class UserSettingForm(forms.ModelForm): 
> >  class Meta: 
> >model = StUserSetting 
> >fields = ( 'default_language', 'prim_currency', 
> 'number_format', 
> > 'decimal_format', 
> > 'date_format', 'time_format', 'currency_format', 
> > 'currency_position', 'financial_year_start', 
> >  'week_start', 'estimate_default_tab', 
> 'invoice_default_tab',) 
> > 
> > **View.py** 
> > 
> > 
> > class CreateUpadateUserSetting(LoginRequiredMixin, FormView): 
> >  template_name = 'settings/user_settings.html' 
> >  form_class = UserSettingForm 
> >  success_url = '/user/setting/preference/' 
>
>
> https://docs.djangoproject.com/en/2.1/ref/models/querysets/#update-or-create 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dbe133d7-43ee-4765-b776-925214415ac3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to add form field dynamically?

2018-09-26 Thread Django Lover
I am creating a model form, i need to add a field dynamically can you 
please give me the solution by using your sharp intelligence? 

[image: synm.png]


Product/service are coming from the model field.they are not static.


Add New is unlimited.



please help

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f144ae51-a036-4aeb-94d5-d058a4067489%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to add form field dynamically?

2018-09-26 Thread Django Lover
Hi joel Thank for response.

*I want something like this-*

[image: form.png] 









1- when I click on *add row* button a new Row (*No-2)* will 
create dynamically.
2- In the select *product/service* its an options dropdown. the option 
should have related *model data*(from table product and service list)
3-  when i save all records in the dynamic field save to the database.


I hope it clear to you. but if you need more information please let me know 
i am glad to discuss with you.

:)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/768d0fb2-4155-40c3-b0fc-fc4dbd2ad553%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to add form field dynamically?

2018-09-26 Thread Django Lover
Then What is the solution please let HELP ME?? I know that it will done by 
Jquery but how? I dont Know



On Wednesday, September 26, 2018 at 6:14:07 PM UTC+5:30, Joel wrote:
>
> I don't think django alone can help you here. You need to do that with 
> JavaScript.
>
> On Wed 26 Sep, 2018, 6:01 PM Django Lover,  > wrote:
>
>> Hi joel Thank for response.
>>
>> *I want something like this-*
>>
>> [image: form.png]
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> 1- when I click on *add row* button a new Row (*No-2)* will 
>> create dynamically.
>> 2- In the select *product/service* its an options dropdown. the option 
>> should have related *model data*(from table product and service list)
>> 3-  when i save all records in the dynamic field save to the database.
>>
>>
>> I hope it clear to you. but if you need more information please let me 
>> know i am glad to discuss with you.
>>
>> :)
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/768d0fb2-4155-40c3-b0fc-fc4dbd2ad553%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/768d0fb2-4155-40c3-b0fc-fc4dbd2ad553%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2140d58d-fc8b-4dcf-9acd-d965afa46cbc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.