Re: save() method not working in shell. What are possible causes?

2023-01-19 Thread Artur Rączka
Ok. I solved the problem myself. The pre_save signal was changing my output
every time I used save() method.


W dniu śr., 18.01.2023 o 23:56 Artur Rączka 
napisał(a):

> Hello guys,
>
> What am I missing or doing wrong?
>
> >>> dublin.price
> 40
> >>> dublin.price = 100
> >>> dublin.price
> 100
> >>> dublin.save()
> >>> dublin.price
> 40
>
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/H-WR_IYvNYQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ca959a16-a448-4e73-8846-fb5cba341f9an%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD2QgpuYzwOhLicc5HXzXO1FqTwAJN3Qm_sAu1wBxoWUC%2BoePg%40mail.gmail.com.


Re: save() got an unexpected keyword argument 'force_insert'

2020-04-21 Thread Motaz Hejaze
nice to know, good luck

On Wed, Apr 22, 2020 at 5:35 AM Ahmed Khairy 
wrote:

> Thank you so much it is realyy helpfull. Fixed it
>
> On Tuesday, April 21, 2020 at 11:23:10 PM UTC-4, Motaz Hejaze wrote:
>>
>> check this out
>>
>> https://wsvincent.com/django-allauth-tutorial-custom-user-model/
>>
>> On Wed, Apr 22, 2020 at 5:18 AM Ahmed Khairy 
>> wrote:
>>
>>> What do you mean ?
>>>
>>> On Tuesday, April 21, 2020 at 11:13:16 PM UTC-4, Motaz Hejaze wrote:

 did you define managers ?

 On Wed, Apr 22, 2020 at 5:06 AM Ahmed Khairy 
 wrote:

> Model Form
>
> UserCreationForm
>
> On Tuesday, April 21, 2020 at 11:02:13 PM UTC-4, Motaz Hejaze wrote:
>>
>> what kind of forms is this ? regular form or model form ?
>>
>>
>> On Wed, Apr 22, 2020 at 4:57 AM Ahmed Khairy 
>> wrote:
>>
>>> Hi all,
>>>
>>> Got this unexpected error all of a sudden, how to fix it.
>>>
>>> save() got an unexpected keyword argument 'force_insert'
>>>
>>>
>>>
>>> def register(request):
>>> if request.method == 'POST':
>>> form = UserRegisterForm(request.POST)
>>> if form.is_valid():
>>> form.save()
>>> username = form.cleaned_data.get('username')
>>> messages.success(
>>> request, f
>>> 'Your account has been created! You are now able to log in')
>>> return redirect('login')
>>> else:
>>> form = UserRegisterForm()
>>> return render(request, 'register.html', {'form': 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/be6de004-4a69-4346-8a12-99eced8d76a3%40googlegroups.com
>>> 
>>> .
>>>
>> --
> 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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4a164104-3cab-4d97-a6ac-47b9a3ed98dd%40googlegroups.com
> 
> .
>
 --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/affd82c8-1b8c-46a0-85c0-a3a5c6939abe%40googlegroups.com
>>> 
>>> .
>>>
>> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3983161c-10b7-4e0d-b2ba-8dbf83e3b890%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-f_4Y%3DTNETUSJNEOuoo0iU7e1T-QPEvsK98F1eB9JB0Dg%40mail.gmail.com.


Re: save() got an unexpected keyword argument 'force_insert'

2020-04-21 Thread Ahmed Khairy
Thank you so much it is realyy helpfull. Fixed it 

On Tuesday, April 21, 2020 at 11:23:10 PM UTC-4, Motaz Hejaze wrote:
>
> check this out
>
> https://wsvincent.com/django-allauth-tutorial-custom-user-model/
>
> On Wed, Apr 22, 2020 at 5:18 AM Ahmed Khairy  > wrote:
>
>> What do you mean ? 
>>
>> On Tuesday, April 21, 2020 at 11:13:16 PM UTC-4, Motaz Hejaze wrote:
>>>
>>> did you define managers ?
>>>
>>> On Wed, Apr 22, 2020 at 5:06 AM Ahmed Khairy  
>>> wrote:
>>>
 Model Form 

 UserCreationForm

 On Tuesday, April 21, 2020 at 11:02:13 PM UTC-4, Motaz Hejaze wrote:
>
> what kind of forms is this ? regular form or model form ?
>
>
> On Wed, Apr 22, 2020 at 4:57 AM Ahmed Khairy  
> wrote:
>
>> Hi all, 
>>
>> Got this unexpected error all of a sudden, how to fix it. 
>>
>> save() got an unexpected keyword argument 'force_insert'
>>
>>
>>
>> def register(request):
>> if request.method == 'POST':
>> form = UserRegisterForm(request.POST)
>> if form.is_valid():
>> form.save()
>> username = form.cleaned_data.get('username')
>> messages.success(
>> request, f
>> 'Your account has been created! You are now able to log in')
>> return redirect('login')
>> else:
>> form = UserRegisterForm()
>> return render(request, 'register.html', {'form': 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/be6de004-4a69-4346-8a12-99eced8d76a3%40googlegroups.com
>>  
>> 
>> .
>>
> -- 
 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...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/4a164104-3cab-4d97-a6ac-47b9a3ed98dd%40googlegroups.com
  
 
 .

>>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/affd82c8-1b8c-46a0-85c0-a3a5c6939abe%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3983161c-10b7-4e0d-b2ba-8dbf83e3b890%40googlegroups.com.


Re: save() got an unexpected keyword argument 'force_insert'

2020-04-21 Thread Ahmed Khairy
Thank you so much it realyy helpfull. Fixed it 

On Tuesday, April 21, 2020 at 11:23:10 PM UTC-4, Motaz Hejaze wrote:
>
> check this out
>
> https://wsvincent.com/django-allauth-tutorial-custom-user-model/
>
> On Wed, Apr 22, 2020 at 5:18 AM Ahmed Khairy  > wrote:
>
>> What do you mean ? 
>>
>> On Tuesday, April 21, 2020 at 11:13:16 PM UTC-4, Motaz Hejaze wrote:
>>>
>>> did you define managers ?
>>>
>>> On Wed, Apr 22, 2020 at 5:06 AM Ahmed Khairy  
>>> wrote:
>>>
 Model Form 

 UserCreationForm

 On Tuesday, April 21, 2020 at 11:02:13 PM UTC-4, Motaz Hejaze wrote:
>
> what kind of forms is this ? regular form or model form ?
>
>
> On Wed, Apr 22, 2020 at 4:57 AM Ahmed Khairy  
> wrote:
>
>> Hi all, 
>>
>> Got this unexpected error all of a sudden, how to fix it. 
>>
>> save() got an unexpected keyword argument 'force_insert'
>>
>>
>>
>> def register(request):
>> if request.method == 'POST':
>> form = UserRegisterForm(request.POST)
>> if form.is_valid():
>> form.save()
>> username = form.cleaned_data.get('username')
>> messages.success(
>> request, f
>> 'Your account has been created! You are now able to log in')
>> return redirect('login')
>> else:
>> form = UserRegisterForm()
>> return render(request, 'register.html', {'form': 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/be6de004-4a69-4346-8a12-99eced8d76a3%40googlegroups.com
>>  
>> 
>> .
>>
> -- 
 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...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/4a164104-3cab-4d97-a6ac-47b9a3ed98dd%40googlegroups.com
  
 
 .

>>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/affd82c8-1b8c-46a0-85c0-a3a5c6939abe%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2633ef13-a6a3-449e-ae91-f175cf7ea37a%40googlegroups.com.


Re: save() got an unexpected keyword argument 'force_insert'

2020-04-21 Thread Motaz Hejaze
check this out

https://wsvincent.com/django-allauth-tutorial-custom-user-model/

On Wed, Apr 22, 2020 at 5:18 AM Ahmed Khairy 
wrote:

> What do you mean ?
>
> On Tuesday, April 21, 2020 at 11:13:16 PM UTC-4, Motaz Hejaze wrote:
>>
>> did you define managers ?
>>
>> On Wed, Apr 22, 2020 at 5:06 AM Ahmed Khairy 
>> wrote:
>>
>>> Model Form
>>>
>>> UserCreationForm
>>>
>>> On Tuesday, April 21, 2020 at 11:02:13 PM UTC-4, Motaz Hejaze wrote:

 what kind of forms is this ? regular form or model form ?


 On Wed, Apr 22, 2020 at 4:57 AM Ahmed Khairy 
 wrote:

> Hi all,
>
> Got this unexpected error all of a sudden, how to fix it.
>
> save() got an unexpected keyword argument 'force_insert'
>
>
>
> def register(request):
> if request.method == 'POST':
> form = UserRegisterForm(request.POST)
> if form.is_valid():
> form.save()
> username = form.cleaned_data.get('username')
> messages.success(
> request, f
> 'Your account has been created! You are now able to log in')
> return redirect('login')
> else:
> form = UserRegisterForm()
> return render(request, 'register.html', {'form': 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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/be6de004-4a69-4346-8a12-99eced8d76a3%40googlegroups.com
> 
> .
>
 --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/4a164104-3cab-4d97-a6ac-47b9a3ed98dd%40googlegroups.com
>>> 
>>> .
>>>
>> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/affd82c8-1b8c-46a0-85c0-a3a5c6939abe%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-dwQZmnjuP%3DEKfAQ-6_sGS7ejLrvA_o8VcHh4DYBPA%3DCA%40mail.gmail.com.


Re: save() got an unexpected keyword argument 'force_insert'

2020-04-21 Thread Ahmed Khairy
What do you mean ? 

On Tuesday, April 21, 2020 at 11:13:16 PM UTC-4, Motaz Hejaze wrote:
>
> did you define managers ?
>
> On Wed, Apr 22, 2020 at 5:06 AM Ahmed Khairy  > wrote:
>
>> Model Form 
>>
>> UserCreationForm
>>
>> On Tuesday, April 21, 2020 at 11:02:13 PM UTC-4, Motaz Hejaze wrote:
>>>
>>> what kind of forms is this ? regular form or model form ?
>>>
>>>
>>> On Wed, Apr 22, 2020 at 4:57 AM Ahmed Khairy  
>>> wrote:
>>>
 Hi all, 

 Got this unexpected error all of a sudden, how to fix it. 

 save() got an unexpected keyword argument 'force_insert'



 def register(request):
 if request.method == 'POST':
 form = UserRegisterForm(request.POST)
 if form.is_valid():
 form.save()
 username = form.cleaned_data.get('username')
 messages.success(
 request, f
 'Your account has been created! You are now able to log in')
 return redirect('login')
 else:
 form = UserRegisterForm()
 return render(request, 'register.html', {'form': 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...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/be6de004-4a69-4346-8a12-99eced8d76a3%40googlegroups.com
  
 
 .

>>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/4a164104-3cab-4d97-a6ac-47b9a3ed98dd%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/affd82c8-1b8c-46a0-85c0-a3a5c6939abe%40googlegroups.com.


Re: save() got an unexpected keyword argument 'force_insert'

2020-04-21 Thread Motaz Hejaze
did you define managers ?

On Wed, Apr 22, 2020 at 5:06 AM Ahmed Khairy 
wrote:

> Model Form
>
> UserCreationForm
>
> On Tuesday, April 21, 2020 at 11:02:13 PM UTC-4, Motaz Hejaze wrote:
>>
>> what kind of forms is this ? regular form or model form ?
>>
>>
>> On Wed, Apr 22, 2020 at 4:57 AM Ahmed Khairy 
>> wrote:
>>
>>> Hi all,
>>>
>>> Got this unexpected error all of a sudden, how to fix it.
>>>
>>> save() got an unexpected keyword argument 'force_insert'
>>>
>>>
>>>
>>> def register(request):
>>> if request.method == 'POST':
>>> form = UserRegisterForm(request.POST)
>>> if form.is_valid():
>>> form.save()
>>> username = form.cleaned_data.get('username')
>>> messages.success(
>>> request, f
>>> 'Your account has been created! You are now able to log in')
>>> return redirect('login')
>>> else:
>>> form = UserRegisterForm()
>>> return render(request, 'register.html', {'form': 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/be6de004-4a69-4346-8a12-99eced8d76a3%40googlegroups.com
>>> 
>>> .
>>>
>> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4a164104-3cab-4d97-a6ac-47b9a3ed98dd%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-fDDbB_X01d8HOvOAZSkPegVw_O%3DzbBDVGaWM72V4Xypg%40mail.gmail.com.


Re: save() got an unexpected keyword argument 'force_insert'

2020-04-21 Thread Ahmed Khairy
Model Form 

UserCreationForm

On Tuesday, April 21, 2020 at 11:02:13 PM UTC-4, Motaz Hejaze wrote:
>
> what kind of forms is this ? regular form or model form ?
>
>
> On Wed, Apr 22, 2020 at 4:57 AM Ahmed Khairy  > wrote:
>
>> Hi all, 
>>
>> Got this unexpected error all of a sudden, how to fix it. 
>>
>> save() got an unexpected keyword argument 'force_insert'
>>
>>
>>
>> def register(request):
>> if request.method == 'POST':
>> form = UserRegisterForm(request.POST)
>> if form.is_valid():
>> form.save()
>> username = form.cleaned_data.get('username')
>> messages.success(
>> request, f
>> 'Your account has been created! You are now able to log in')
>> return redirect('login')
>> else:
>> form = UserRegisterForm()
>> return render(request, 'register.html', {'form': 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/be6de004-4a69-4346-8a12-99eced8d76a3%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4a164104-3cab-4d97-a6ac-47b9a3ed98dd%40googlegroups.com.


Re: save() got an unexpected keyword argument 'force_insert'

2020-04-21 Thread Motaz Hejaze
what kind of forms is this ? regular form or model form ?


On Wed, Apr 22, 2020 at 4:57 AM Ahmed Khairy 
wrote:

> Hi all,
>
> Got this unexpected error all of a sudden, how to fix it.
>
> save() got an unexpected keyword argument 'force_insert'
>
>
>
> def register(request):
> if request.method == 'POST':
> form = UserRegisterForm(request.POST)
> if form.is_valid():
> form.save()
> username = form.cleaned_data.get('username')
> messages.success(
> request, f
> 'Your account has been created! You are now able to log in')
> return redirect('login')
> else:
> form = UserRegisterForm()
> return render(request, 'register.html', {'form': 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/be6de004-4a69-4346-8a12-99eced8d76a3%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-fvxt2655FMSMcBoRamCKHEVHY89ZMDwQp%3D6rPxaN2TLw%40mail.gmail.com.


Re: ""Save" method throws duplicate key value violates unique constraint

2020-04-07 Thread Menaga Gopal
Thank you for the response.

I was able to fix it by setting "user" field as the primary key in 
UserProperties model.

Below is the updated version of the user field in UserProperties model. 
Just added "primary_key=True" to fix the duplicate key value issue.

class UserProperties(models.Model):
user = models.OneToOneField(CustomUser, on_delete= models.CASCADE,
primary_key=True)

On Tuesday, April 7, 2020 at 4:10:00 AM UTC+2, VenkataSivaRamiReddy wrote:
>
> Use in place of one to one model field place foreign key field
>
> On Tue, Apr 7, 2020, 05:15 Menaga Gopal > 
> wrote:
>
>>
>>
>>
>>
>> Hello,
>>
>> I have 2 tables:
>>
>> 1) CustomUser table
>>  - Id 
>>  - Email
>>  - Name
>>
>> 2) UserProperties table
>>  - id
>>  - user (foreign key with one to one relationship)
>>  - address
>>  - payment_details
>>
>>
>>   -  have mapped one to one relationship for the field "user" in the 
>> UserProperties table as below.
>>
>> user = models.OneToOneField(CustomUser, on_delete= models.CASCADE)
>>
>>   - Below is my view.py. When I try to save the user profile, the data is 
>> saved for the very first time (ie., when there is no such record for the 
>> user in the Userproperties table. However when I try to update the same 
>> user profile I get Integrity error.
>>
>> IntegrityError at /users/profile
>>
>> duplicate key value violates unique constraint 
>> "users_userproperties_user_id_key"
>> DETAIL:  Key (user_id)=(4) already exists.
>>
>>
>>
>> @login_required
>> def profile(request):
>> if request.method == 'POST':
>> profile_form = UserProfileForm(request.POST)
>> if profile_form.is_valid():
>> profile = profile_form.save(commit=False) 
>> profile.user = request.user
>> profile.save()
>> messages.success(request, f'Your Profile has been updated.')
>> return redirect('profile')
>> else:
>> profile_form = UserProfileForm()
>> return render(request,'profile.html',{'profile_form': profile_form})
>>
>> I am new to django, please help me solve this issue.
>>
>>
>> Thanks 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/580f2a57-eda2-49f9-b42c-b9885ffd82f8%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b22715c8-f9be-4836-916c-03a1f80fa75c%40googlegroups.com.


Re: ""Save" method throws duplicate key value violates unique constraint

2020-04-06 Thread VenkataSivaRamiReddy
Use in place of one to one model field place foreign key field

On Tue, Apr 7, 2020, 05:15 Menaga Gopal  wrote:

>
>
>
>
> Hello,
>
> I have 2 tables:
>
> 1) CustomUser table
>  - Id
>  - Email
>  - Name
>
> 2) UserProperties table
>  - id
>  - user (foreign key with one to one relationship)
>  - address
>  - payment_details
>
>
>   -  have mapped one to one relationship for the field "user" in the
> UserProperties table as below.
>
> user = models.OneToOneField(CustomUser, on_delete= models.CASCADE)
>
>   - Below is my view.py. When I try to save the user profile, the data is
> saved for the very first time (ie., when there is no such record for the
> user in the Userproperties table. However when I try to update the same
> user profile I get Integrity error.
>
> IntegrityError at /users/profile
>
> duplicate key value violates unique constraint 
> "users_userproperties_user_id_key"
> DETAIL:  Key (user_id)=(4) already exists.
>
>
>
> @login_required
> def profile(request):
> if request.method == 'POST':
> profile_form = UserProfileForm(request.POST)
> if profile_form.is_valid():
> profile = profile_form.save(commit=False)
> profile.user = request.user
> profile.save()
> messages.success(request, f'Your Profile has been updated.')
> return redirect('profile')
> else:
> profile_form = UserProfileForm()
> return render(request,'profile.html',{'profile_form': profile_form})
>
> I am new to django, please help me solve this issue.
>
>
> Thanks 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/580f2a57-eda2-49f9-b42c-b9885ffd82f8%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGiJVX0JbkDzk_M1fMgRntmw7%2Bkz%3D2X_%3D4Ts%2BgNm46oqoduooA%40mail.gmail.com.


Re: Save partial state of a page when reloading

2019-10-13 Thread Robert Levasseur
Hi, 

I felt like I knew it was simple question haha, thanks so much for 
answering though! I will try all of these right away!

Thank you again!

On Saturday, October 12, 2019 at 12:15:00 AM UTC-4, WD Wang wrote:
>
> hi,
>
> I think It's not a django problem, it's a classic web developing problem.
>
> Http is stateless, if you want to 'save' something, you need to use 
> 1. URL param like the 'q=soccer'.
> 2. Use cookie/session.
>
> I think your problem can be solved by one of the methods below:
> 1. Use ajax to do the search, and use javascript to update the search 
> result, so the page will not be reload when doing search.
> 2. Put the search box and category check-boxes in one form, when the user 
> submit to search, the browser will also submit the categories check boxes, 
> so you know what the user selected, you can select them again in the 
> response html.
> 3. Use javascript to remember what category the user selected, and render 
> the selection when the page reloaded.
>
> On Sat, Oct 12, 2019 at 5:07 AM Robert Levasseur  > wrote:
>
>> Hi, 
>>
>> I'm very new to Django so this might be a silly question, but I'm having 
>> an issue with the filter functionality on my site's search page. I am using 
>> the django-haystack module to interface with the Whoosh search engine, and 
>> it functions by reloading the page while sending the query as a GET 
>> parameter. This means when someone runs the search, say for soccer, on the 
>> site it loads the page with a url /search/?q=soccer 
>> On the same page I have a from with a bunch of category check-boxes that 
>> I would like to use to filter the search results. I run into the problem 
>> however that if I submit the form and reload the page it does not remember 
>> the search text, and If I run the search and reload the page it does not 
>> remember which categories were selected.
>>
>> Is there a way in Django for me to pull both of these pieces of 
>> information and mess around with them in views.py, while maintaining the 
>> state of the category form and search box? Sorry if this is a strange 
>> question, and thanks for any help!
>>
>> Regards,
>> R. Eli
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/a25b09a0-be13-4f18-8752-ea1bb6b9f1a0%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a5a01e79-3151-49ae-86ae-ff997a358eff%40googlegroups.com.


Re: Save partial state of a page when reloading

2019-10-11 Thread wd
hi,

I think It's not a django problem, it's a classic web developing problem.

Http is stateless, if you want to 'save' something, you need to use
1. URL param like the 'q=soccer'.
2. Use cookie/session.

I think your problem can be solved by one of the methods below:
1. Use ajax to do the search, and use javascript to update the search
result, so the page will not be reload when doing search.
2. Put the search box and category check-boxes in one form, when the user
submit to search, the browser will also submit the categories check boxes,
so you know what the user selected, you can select them again in the
response html.
3. Use javascript to remember what category the user selected, and render
the selection when the page reloaded.

On Sat, Oct 12, 2019 at 5:07 AM Robert Levasseur  wrote:

> Hi,
>
> I'm very new to Django so this might be a silly question, but I'm having
> an issue with the filter functionality on my site's search page. I am using
> the django-haystack module to interface with the Whoosh search engine, and
> it functions by reloading the page while sending the query as a GET
> parameter. This means when someone runs the search, say for soccer, on the
> site it loads the page with a url /search/?q=soccer
> On the same page I have a from with a bunch of category check-boxes that I
> would like to use to filter the search results. I run into the problem
> however that if I submit the form and reload the page it does not remember
> the search text, and If I run the search and reload the page it does not
> remember which categories were selected.
>
> Is there a way in Django for me to pull both of these pieces of
> information and mess around with them in views.py, while maintaining the
> state of the category form and search box? Sorry if this is a strange
> question, and thanks for any help!
>
> Regards,
> R. Eli
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a25b09a0-be13-4f18-8752-ea1bb6b9f1a0%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABexzmhcqSGOs6NgkEzZAS7uL4URZRqV6X-sjqPQDBK9cH7nqQ%40mail.gmail.com.


Re: save cropped image with PIL to database

2017-07-13 Thread 'Tom Evans' via Django users
On Mon, Jul 3, 2017 at 11:09 AM, shahab emami  wrote:
> hello
>
> i have a question and i cant find answer with search.
>
> i want to save cropped image in database then :
> this is my model:
>
> class Photo(models.Model):
> file= models.ImageField(upload_to='%Y/%m/%d',
> blank=True,null=True)
>
>
> i have a form then user can select image and send to view like this:
>
> 
> {% csrf_token %}
>
>   
>
> 
>
>   
>
>
> and in the view i have this :
>
> from PIL import Image
>
>
> def save_photo(request):
>
> _photo, created = models.Photo.objects.get_or_create(pk=1)
>
> if request.method == 'POST':
> photo = request.FILES.get('file')

This is a django.core.files.File (or subclass) object. It is file-like
and can be treated as a file.

>
> image = Image.open(photo)
>
> cropped_image = image.crop((100, 100, 200, 200))
> resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS)

resized_image is a pil.Image. Again, it is file-like, but it is not a
django.core.files.File...

> _photo.file = resized_image
> _photo.save()

so this doesn't work. You will need to wrap the PIL.Image file-like
object with the django File class (remember appropriate imports):

_photo.file = File(resized_image)
_photo.save()


Cheers

Tom

-- 
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/CAFHbX1%2BTeg-joCvt%3DosHTThpzduQ0_ZYr%2BKvMfbD%3DJJPHZ2gcw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: save cropped image with PIL to database

2017-07-06 Thread Melvyn Sopacua
On Monday 03 July 2017 03:09:56 shahab emami wrote:
> hello
> 
> i have a question and i cant find answer with search.

Really?
https://duckduckgo.com/?q=django+resize+image=ffsb=
software

-- 
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/15394513.8HkvbzOazS%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: save cropped image with PIL to database

2017-07-04 Thread Andréas Kühne
Sorry - can't help you there. I prefer using pip packages than writing my
own code - where possible. :-)

Regards,

Andréas

2017-07-04 10:15 GMT+02:00 shahab emami :

> but i want to do it myself.
>
> when i write code i can improve it as much as i can.
> can anybody please tell me about my mistake please
>
> On Monday, July 3, 2017 at 9:12:55 PM UTC+4:30, Andréas Kühne wrote:
>>
>> I would have a look at the easy-thumbnails plugin (
>> http://easy-thumbnails.readthedocs.io/en/2.1/). It uses pillow behind
>> the scenes and it is very easy to do the cropping and everything that you
>> need and you don't need to write it yourself :-)
>>
>> Regards,
>>
>> Andréas
>>
>> 2017-07-03 12:09 GMT+02:00 shahab emami :
>>
>>> hello
>>>
>>> i have a question and i cant find answer with search.
>>>
>>> i want to save cropped image in database then :
>>> this is my model:
>>>
>>> class Photo(models.Model):
>>> file= models.ImageField(upload_to='%Y/%m/%d', 
>>> blank=True,null=True)
>>>
>>>
>>> i have a form then user can select image and send to view like this:
>>>
>>> 
>>> {% csrf_token %}
>>>
>>>   
>>>
>>> 
>>>
>>>   
>>>
>>>
>>> and in the view i have this :
>>>
>>> from PIL import Image
>>>
>>>
>>> def save_photo(request):
>>>
>>> _photo, created = models.Photo.objects.get_or_create(pk=1)
>>>
>>> if request.method == 'POST':
>>> photo = request.FILES.get('file')
>>>
>>> image = Image.open(photo)
>>>
>>> cropped_image = image.crop((100, 100, 200, 200))
>>> resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS)
>>> _photo.file = resized_image
>>> _photo.save()
>>>
>>>
>>> return HttpResponse("your image has been saved")
>>>
>>>
>>>
>>>
>>>
>>> but i get this error:
>>>
>>> 'Image' object has no attribute '_committed'
>>>
>>>
>>>
>>> i'm sure my mistake is in views.py but i dont now how to fix it. how can
>>> put resized_image that is an object of Image class to
>>> a model.
>>> can you help me please?
>>>
>>>
>>> --
>>> 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/ms
>>> gid/django-users/362887c4-6b41-47e2-a9f5-f4a129b2538d%40googlegroups.com
>>> 
>>> .
>>> 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/7be760c5-b5e3-4066-bb27-e953e829d68c%40googlegroups.com
> 
> .
>
> 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/CAK4qSCciZ86du_A9K8ShTdnDNpy1W7%2BA7o_0pspLeVZcv%2BGBwg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: save cropped image with PIL to database

2017-07-04 Thread shahab emami
but i want to do it myself.

when i write code i can improve it as much as i can. 
can anybody please tell me about my mistake please

On Monday, July 3, 2017 at 9:12:55 PM UTC+4:30, Andréas Kühne wrote:
>
> I would have a look at the easy-thumbnails plugin (
> http://easy-thumbnails.readthedocs.io/en/2.1/). It uses pillow behind the 
> scenes and it is very easy to do the cropping and everything that you need 
> and you don't need to write it yourself :-)
>
> Regards,
>
> Andréas
>
> 2017-07-03 12:09 GMT+02:00 shahab emami 
> :
>
>> hello
>>
>> i have a question and i cant find answer with search.
>>
>> i want to save cropped image in database then :
>> this is my model:
>>
>> class Photo(models.Model):
>> file= models.ImageField(upload_to='%Y/%m/%d', 
>> blank=True,null=True)
>>
>>
>> i have a form then user can select image and send to view like this:
>>
>> 
>> {% csrf_token %}
>>
>>   
>>
>> 
>>
>>   
>>
>>
>> and in the view i have this :
>>
>> from PIL import Image
>>
>>
>> def save_photo(request):
>>
>> _photo, created = models.Photo.objects.get_or_create(pk=1)
>>
>> if request.method == 'POST':
>> photo = request.FILES.get('file')
>>
>> image = Image.open(photo)
>>
>> cropped_image = image.crop((100, 100, 200, 200))
>> resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS)
>> _photo.file = resized_image
>> _photo.save()
>>
>>
>> return HttpResponse("your image has been saved")
>>
>>
>>
>>
>>
>> but i get this error:
>>
>> 'Image' object has no attribute '_committed'
>>
>>
>>
>> i'm sure my mistake is in views.py but i dont now how to fix it. how can 
>> put resized_image that is an object of Image class to 
>> a model.
>> can you help me please?
>>
>>
>> -- 
>> 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/362887c4-6b41-47e2-a9f5-f4a129b2538d%40googlegroups.com
>>  
>> 
>> .
>> 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/7be760c5-b5e3-4066-bb27-e953e829d68c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: save cropped image with PIL to database

2017-07-03 Thread Andréas Kühne
I would have a look at the easy-thumbnails plugin (
http://easy-thumbnails.readthedocs.io/en/2.1/). It uses pillow behind the
scenes and it is very easy to do the cropping and everything that you need
and you don't need to write it yourself :-)

Regards,

Andréas

2017-07-03 12:09 GMT+02:00 shahab emami :

> hello
>
> i have a question and i cant find answer with search.
>
> i want to save cropped image in database then :
> this is my model:
>
> class Photo(models.Model):
> file= models.ImageField(upload_to='%Y/%m/%d', 
> blank=True,null=True)
>
>
> i have a form then user can select image and send to view like this:
>
> 
> {% csrf_token %}
>
>   
>
> 
>
>   
>
>
> and in the view i have this :
>
> from PIL import Image
>
>
> def save_photo(request):
>
> _photo, created = models.Photo.objects.get_or_create(pk=1)
>
> if request.method == 'POST':
> photo = request.FILES.get('file')
>
> image = Image.open(photo)
>
> cropped_image = image.crop((100, 100, 200, 200))
> resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS)
> _photo.file = resized_image
> _photo.save()
>
>
> return HttpResponse("your image has been saved")
>
>
>
>
>
> but i get this error:
>
> 'Image' object has no attribute '_committed'
>
>
>
> i'm sure my mistake is in views.py but i dont now how to fix it. how can
> put resized_image that is an object of Image class to
> a model.
> can you help me please?
>
>
> --
> 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/362887c4-6b41-47e2-a9f5-f4a129b2538d%40googlegroups.com
> 
> .
> 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/CAK4qSCfrSH%3DWxjuqgcgasE4_Q6kxEeNGtG8oQ_jQKAF1xo23cw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: save() prohibited to prevent data loss due to unsaved related object 'committee'

2015-10-21 Thread Tim Graham
You need to call super() in your custom method to ensure the object is 
actually saved to the database.

On Wednesday, October 21, 2015 at 8:12:24 AM UTC-4, Yaniv Mirel wrote:
>
> The Committee.save() is:
> def save(self, *args, **kwargs):
>if not self.slug:
>self.slug = 'committee-%s' % self.id
>
> And yes, after removing that save function everything works fine.
>
> On Tuesday, October 20, 2015 at 9:32:20 PM UTC+3, Tim Graham wrote:
>>
>> What does the Committee.save() method look like? You have no problem if 
>> you remove that method?
>>
>> On Tuesday, October 20, 2015 at 2:22:24 PM UTC-4, Yaniv Mirel wrote:
>>>
>>> I've found out that this error is happening because I also have a def 
>>> save() function on the committee model.
>>> So I am not sure if this is a bug or I am not suppose to have it like 
>>> that.
>>>
>>> On Tuesday, October 20, 2015 at 9:02:27 PM UTC+3, Yaniv Mirel wrote:

 Hi,

 I am getting this error when running model post save signal.
 The error traceback is for gr.save()

 it seems like the committee model is not saving before it need to be 
 assigned to GroupRole model as a FK.

 this is the post_save signal code.



 @receiver(post_save, sender=Community)
 def set_default_reasons(sender, instance, created, 
 dispatch_uid='set_default_reasons', **kwargs):

 if created:

 committee = Committee(community=instance, name='Board', slug='main')

 committee.save()


 for group_role in settings.DEFAULT_GROUP_ROLES:

 gr = GroupRole(committee=committee, 
 role=instance.roles.get(title=group_role), 
 group=instance.groups.get(title=group_role)) 

 gr.save() 

  

  Thanks.

>>>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/76e9de0d-852c-4f8b-9fbb-591ba22b68c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: save() prohibited to prevent data loss due to unsaved related object 'committee'

2015-10-21 Thread Yaniv Mirel
The Committee.save() is:
def save(self, *args, **kwargs):
   if not self.slug:
   self.slug = 'committee-%s' % self.id

And yes, after removing that save function everything works fine.

On Tuesday, October 20, 2015 at 9:32:20 PM UTC+3, Tim Graham wrote:
>
> What does the Committee.save() method look like? You have no problem if 
> you remove that method?
>
> On Tuesday, October 20, 2015 at 2:22:24 PM UTC-4, Yaniv Mirel wrote:
>>
>> I've found out that this error is happening because I also have a def 
>> save() function on the committee model.
>> So I am not sure if this is a bug or I am not suppose to have it like 
>> that.
>>
>> On Tuesday, October 20, 2015 at 9:02:27 PM UTC+3, Yaniv Mirel wrote:
>>>
>>> Hi,
>>>
>>> I am getting this error when running model post save signal.
>>> The error traceback is for gr.save()
>>>
>>> it seems like the committee model is not saving before it need to be 
>>> assigned to GroupRole model as a FK.
>>>
>>> this is the post_save signal code.
>>>
>>>
>>>
>>> @receiver(post_save, sender=Community)
>>> def set_default_reasons(sender, instance, created, 
>>> dispatch_uid='set_default_reasons', **kwargs):
>>>
>>> if created:
>>>
>>> committee = Committee(community=instance, name='Board', slug='main')
>>>
>>> committee.save()
>>>
>>>
>>> for group_role in settings.DEFAULT_GROUP_ROLES:
>>>
>>> gr = GroupRole(committee=committee, 
>>> role=instance.roles.get(title=group_role), 
>>> group=instance.groups.get(title=group_role)) 
>>>
>>> gr.save() 
>>>
>>>  
>>>
>>>  Thanks.
>>>
>>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cb36759c-8d87-4a07-8700-bc0f30121ef0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: save() prohibited to prevent data loss due to unsaved related object 'committee'

2015-10-20 Thread Tim Graham
What does the Committee.save() method look like? You have no problem if you 
remove that method?

On Tuesday, October 20, 2015 at 2:22:24 PM UTC-4, Yaniv Mirel wrote:
>
> I've found out that this error is happening because I also have a def 
> save() function on the committee model.
> So I am not sure if this is a bug or I am not suppose to have it like that.
>
> On Tuesday, October 20, 2015 at 9:02:27 PM UTC+3, Yaniv Mirel wrote:
>>
>> Hi,
>>
>> I am getting this error when running model post save signal.
>> The error traceback is for gr.save()
>>
>> it seems like the committee model is not saving before it need to be 
>> assigned to GroupRole model as a FK.
>>
>> this is the post_save signal code.
>>
>>
>>
>> @receiver(post_save, sender=Community)
>> def set_default_reasons(sender, instance, created, 
>> dispatch_uid='set_default_reasons', **kwargs):
>>
>> if created:
>>
>> committee = Committee(community=instance, name='Board', slug='main')
>>
>> committee.save()
>>
>>
>> for group_role in settings.DEFAULT_GROUP_ROLES:
>>
>> gr = GroupRole(committee=committee, 
>> role=instance.roles.get(title=group_role), 
>> group=instance.groups.get(title=group_role)) 
>>
>> gr.save() 
>>
>>  
>>
>>  Thanks.
>>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/222e6fcc-9b07-4d9f-8ea4-efc4d835d4a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: save() prohibited to prevent data loss due to unsaved related object 'committee'

2015-10-20 Thread Yaniv Mirel
I've found out that this error is happening because I also have a def 
save() function on the committee model.
So I am not sure if this is a bug or I am not suppose to have it like that.

On Tuesday, October 20, 2015 at 9:02:27 PM UTC+3, Yaniv Mirel wrote:
>
> Hi,
>
> I am getting this error when running model post save signal.
> The error traceback is for gr.save()
>
> it seems like the committee model is not saving before it need to be assigned 
> to GroupRole model as a FK.
>
> this is the post_save signal code.
>
>
>
> @receiver(post_save, sender=Community)
> def set_default_reasons(sender, instance, created, 
> dispatch_uid='set_default_reasons', **kwargs):
>
> if created:
>
> committee = Committee(community=instance, name='Board', slug='main')
>
> committee.save()
>
>
> for group_role in settings.DEFAULT_GROUP_ROLES:
>
> gr = GroupRole(committee=committee, 
> role=instance.roles.get(title=group_role), 
> group=instance.groups.get(title=group_role)) 
>
> gr.save() 
>
>  
>
>  Thanks.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8f2927d2-27f3-4be9-8d51-f171320ed361%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Save one to one field manually

2015-02-02 Thread Paul Royik
I solved the problem.
See 
http://stackoverflow.com/questions/28262236/saving-onetoone-field-manually-in-django

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/16fc6f58-8260-48c8-bb46-7f5ec5092f34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Save data from form

2014-09-08 Thread Eddilbert Macharia
Hello,

Your welcome, its not that difficult to wrap head around django though, 
just patience is required

Regards,
Eddilbert Macharia.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f8443d32-849f-4b1f-aacb-b2e261d76372%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Save data from form

2014-09-07 Thread Артём Мутерко
Thank you a lot for reply. I thought I could cover Django on fly, but it 
seems like I have to read some books before. Anyway thank you very much!

воскресенье, 7 сентября 2014 г., 10:50:55 UTC+3 пользователь Eddilbert 
Macharia написал:
>
> Hi Aptem,
>
> Your questions is not clearly what exactly do you want, where are you 
> stuck, specifically,
> Check this it might assist you 
> https://docs.djangoproject.com/en/1.7/topics/forms/
>
> this is a very basic example if you have an organization mode below
>
> models.py
>
>> class Organization(models.Model):
>>
> name = models.CharField(max_length=25) 
>
> create a forms module and add this
> form.py
> class NameForm(form.Form):
> name = forms.CharField(max_length=25)
>  
>
>>  view.py
>
> import the model and form to you view
>
>> def organization_save(request):
>> # if this is a POST request we need to process the form data
>> if request.method == 'POST':
>> # create a form instance and populate it with data from the request:
>> form = NameForm(request.POST)
>> # check whether it's valid:
>> if form.is_valid():
>> # process the data in form.cleaned_data as required
>>
>> cleaned_name = form.cleaned_data['name'] 
>
>> # save form if its new organization creation
>>
>>  organization = Organization.objects.create(name=cleaned_name)
> # if its an existing organizanization
> organization = Organization.objects.get(id='the id of the organization')
> organization .name = cleaned_name
> organization .save()
>
>> # redirect to a new URL:
>> return HttpResponseRedirect('/thanks/')
>>
>> # if a GET (or any other method) we'll create a blank form
>> else:
>> form = NameForm()
>>
>> return render(request, 'name.html', {'form': form})
>>
>>
>
> there is an easier way of doing this by use of modelforms check this out  
> https://docs.djangoproject.com/en/1.7/topics/forms/modelforms/
>
> Hope it assists you.
>
> Regards,
> Eddilbert Macharia.
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/61b0994b-5d25-4ef1-bac7-23475e33f745%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Save data from form

2014-09-07 Thread Eddilbert Macharia
Hi Aptem,

Your questions is not clearly what exactly do you want, where are you 
stuck, specifically,
Check this it might assist you 
https://docs.djangoproject.com/en/1.7/topics/forms/

this is a very basic example if you have an organization mode below

models.py

> class Organization(models.Model):
>
name = models.CharField(max_length=25) 

create a forms module and add this
form.py
class NameForm(form.Form):
name = forms.CharField(max_length=25)
 

>  view.py

import the model and form to you view

> def organization_save(request):
> # if this is a POST request we need to process the form data
> if request.method == 'POST':
> # create a form instance and populate it with data from the request:
> form = NameForm(request.POST)
> # check whether it's valid:
> if form.is_valid():
> # process the data in form.cleaned_data as required
>
> cleaned_name = form.cleaned_data['name'] 

> # save form if its new organization creation
>
>  organization = Organization.objects.create(name=cleaned_name)
# if its an existing organizanization
organization = Organization.objects.get(id='the id of the organization')
organization .name = cleaned_name
organization .save()

> # redirect to a new URL:
> return HttpResponseRedirect('/thanks/')
>
> # if a GET (or any other method) we'll create a blank form
> else:
> form = NameForm()
>
> return render(request, 'name.html', {'form': form})
>
>

there is an easier way of doing this by use of modelforms check this out  
https://docs.djangoproject.com/en/1.7/topics/forms/modelforms/

Hope it assists you.

Regards,
Eddilbert Macharia.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/29ee3516-d1a2-4840-85e7-018c1c7d8c1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Save django queries for reuse

2014-06-01 Thread Derek
You have not given enough details on your reporting setup; so my guess 
would be to save the details into a new table.  This would include data 
such as:

* id (for the record)
* user_id
* report_id
* date_time
* parameters

The "parameters" are  a text field; with the criteria/parameters which 
created the report saved as a JSON object.  That way if the report gets 
extended you can still retrieve at least some of the criteria from the JSON 
data.

You might also want to allow the allow the user to give their own 
Title/Name to the report so they can more easily find it again (assuming 
you give them a list to choose from); and perhaps the option to make it 
private/public, depending on your setup.

But one thing you do not want to do is save the actual data from the 
report!!

HTH.

On Saturday, 31 May 2014 23:41:53 UTC+2, lovesh harchandani wrote:
>
> In my application a user can generate reports on multiple models using 
> multiple criteria. I want to let the user save the queries(with the 
> criteria). What is a good approach?
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5c2290dc-4765-4a3b-9765-f89f1af7d5d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Save to User table first_name and last_name from a page with a different form

2014-01-22 Thread Brad Rice
I think I figured it out. The user is on the reuqest so it was pretty easy.

def form_valid(self, form):
obj = form.save(commit=False)
obj.created_by = self.request.user
obj.application_id = self.kwargs['app_id']
u = self.request.user
u.last_name = obj.last_name;
u.first_name = obj.first_name;
obj.save()
u.save()
#reverse_lazy = lambda name=answers, *args : lazy(reverse, 
str)(name, args=args)
return HttpResponseRedirect(reverse('requestform:answers', 
kwargs={'app_id': obj.application_id}))


On Wednesday, January 22, 2014 9:48:27 AM UTC-5, Brad Rice wrote:
>
> I have a registration and login page that only takes username and 
> password. After they register or login, they are taken to a profile form 
> where they can provide additional information such as address and phone 
> numbers. I'm using a Model Form CreateView there. On that page I want the 
> First Name and Last Name fields to  save to the auth_user table rather than 
> that Profile Form model. How do I have two fields submit data to the 
> auth_user table and the other fields submit to the Profile table?
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dcf1ea7c-92fb-405b-885d-9656c91d782f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Save the user from one model to the another model

2013-12-03 Thread Aamu Padi
Thank you all so much for the answers! I came up with this solution.

class Message(models.Model):
thread = models.ForeignKey(Thread)
sent_date = models.DateTimeField(default=datetime.now)
sender = models.ForeignKey(User)
body = models.TextField()
is_hidden = models.ManyToManyField(User, related_name='hidden_message',
blank=True)

def __unicode__(self):
return "%s - %s - %s" % (unicode(self.thread.id), self.body,
self.sender)

def save(self, *args, **kwargs):
probably_new = (self.pk is None)
super(Message, self).save(*args, **kwargs)
if probably_new:
self.thread.user.add(self.sender)

Please correct me, if this is not a good option. But with signals I can
check whether its a new created message or not. Does this have any draw
backs? Thank you once again!


On Tue, Dec 3, 2013 at 8:22 PM, antialiasis  wrote:

> I believe what Aamu Padi is getting at is that he doesn't want to do this
> in the view at all. He just wants it to happen *whenever* a Message is
> created. That's a textbook use case for signals.
>
> On Tuesday, December 3, 2013 1:14:50 PM UTC, Timothy W. Cook wrote:
>>
>> On Tue, Dec 3, 2013 at 9:56 AM, Aamu Padi  wrote:
>> > Ok! Plural names. Got it. But I was looking for something more of a
>> > overriding the save method for the Thread class, so that I don't have
>> to do
>> > that in the view.
>> >
>>
>> You can do it in the same view as the message.  You aren't limited to
>> working with only one model in a view.
>>
>> HTH,
>> Tim
>>
>>
>>
>>
>> >
>> > On Tue, Dec 3, 2013 at 1:39 PM,  wrote:
>> >>
>> >> You're probably looking for something along the lines of:
>> >>
>> >> thread = Thread.objects.get(id=)
>> >> msg = Message.objects.get(id=)
>> >>
>> >> thread.user.add(msg.sender)
>> >>
>> >> Look at add() and remove() methods in documentation (search for
>> related
>> >> managers).
>> >>
>> >> FYI - it's a good practice to name fields that use ManyToMany field in
>> >> plural, i.e. Thread.users would be better than Thread.user
>> >>
>> >> HTH
>> >>
>> >> Jirka
>> >> 
>> >> From: Aamu Padi 
>> >> Sender: django...@googlegroups.com
>> >> Date: Tue, 3 Dec 2013 04:19:55 +0530
>> >> To: 
>> >> ReplyTo: django...@googlegroups.com
>> >> Subject: Save the user from one model to the another model
>> >>
>> >> What I want to do is, whenever I create a new message, I want the
>> sender
>> >> of the Message to be added to the user of the Thread. How do I do
>> that?
>> >>
>> >>>
>> >>> class Thread(models.Model):
>> >>> user = models.ManyToManyField(User)
>> >>> is_hidden = models.ManyToManyField(User,
>> >>> related_name='hidden_thread', blank=True)
>> >>>
>> >>> def __unicode__(self):
>> >>> return unicode(self.id)
>> >>>
>> >>> class Message(models.Model):
>> >>> thread = models.ForeignKey(Thread)
>> >>> sent_date = models.DateTimeField(default=datetime.now)
>> >>> sender = models.ForeignKey(User)
>> >>> body = models.TextField()
>> >>> is_hidden = models.ManyToManyField(User,
>> >>> related_name='hidden_message', blank=True)
>> >>>
>> >>> def __unicode__(self):
>> >>> return "%s - %s" % (unicode(self.thread.id), self.body)
>> >>>
>> >> --
>> >> 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 http://groups.google.com/group/django-users.
>> >> To view this discussion on the web visit
>> >> https://groups.google.com/d/msgid/django-users/
>> CAHSNPWveL8rqDLenDLayGrtC_RAwQ-Pfp0SYravr7%2BuJzhBhXw%40mail.gmail.com.
>> >> For more options, visit https://groups.google.com/groups/opt_out.
>> >>
>> >> --
>> >> 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 http://groups.google.com/group/django-users.
>> >> To view this discussion on the web visit
>> >> https://groups.google.com/d/msgid/django-users/495305343-
>> 1386058174-cardhu_decombobulator_blackberry.rim.net-1176089190-%40b17.c3.
>> bise7.blackberry.
>> >> For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>> > --
>> > 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 

Re: Save the user from one model to the another model

2013-12-03 Thread antialiasis
I believe what Aamu Padi is getting at is that he doesn't want to do this 
in the view at all. He just wants it to happen *whenever* a Message is 
created. That's a textbook use case for signals.

On Tuesday, December 3, 2013 1:14:50 PM UTC, Timothy W. Cook wrote:
>
> On Tue, Dec 3, 2013 at 9:56 AM, Aamu Padi  
> wrote: 
> > Ok! Plural names. Got it. But I was looking for something more of a 
> > overriding the save method for the Thread class, so that I don't have to 
> do 
> > that in the view. 
> > 
>
> You can do it in the same view as the message.  You aren't limited to 
> working with only one model in a view. 
>
> HTH, 
> Tim 
>
>
>
>
> > 
> > On Tue, Dec 3, 2013 at 1:39 PM,  
> wrote: 
> >> 
> >> You're probably looking for something along the lines of: 
> >> 
> >> thread = Thread.objects.get(id=) 
> >> msg = Message.objects.get(id=) 
> >> 
> >> thread.user.add(msg.sender) 
> >> 
> >> Look at add() and remove() methods in documentation (search for related 
> >> managers). 
> >> 
> >> FYI - it's a good practice to name fields that use ManyToMany field in 
> >> plural, i.e. Thread.users would be better than Thread.user 
> >> 
> >> HTH 
> >> 
> >> Jirka 
> >>  
> >> From: Aamu Padi  
> >> Sender: django...@googlegroups.com  
> >> Date: Tue, 3 Dec 2013 04:19:55 +0530 
> >> To:  
> >> ReplyTo: django...@googlegroups.com  
> >> Subject: Save the user from one model to the another model 
> >> 
> >> What I want to do is, whenever I create a new message, I want the 
> sender 
> >> of the Message to be added to the user of the Thread. How do I do that? 
> >> 
> >>> 
> >>> class Thread(models.Model): 
> >>> user = models.ManyToManyField(User) 
> >>> is_hidden = models.ManyToManyField(User, 
> >>> related_name='hidden_thread', blank=True) 
> >>> 
> >>> def __unicode__(self): 
> >>> return unicode(self.id) 
> >>> 
> >>> class Message(models.Model): 
> >>> thread = models.ForeignKey(Thread) 
> >>> sent_date = models.DateTimeField(default=datetime.now) 
> >>> sender = models.ForeignKey(User) 
> >>> body = models.TextField() 
> >>> is_hidden = models.ManyToManyField(User, 
> >>> related_name='hidden_message', blank=True) 
> >>> 
> >>> def __unicode__(self): 
> >>> return "%s - %s" % (unicode(self.thread.id), self.body) 
> >>> 
> >> -- 
> >> 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 http://groups.google.com/group/django-users. 
> >> To view this discussion on the web visit 
> >> 
> https://groups.google.com/d/msgid/django-users/CAHSNPWveL8rqDLenDLayGrtC_RAwQ-Pfp0SYravr7%2BuJzhBhXw%40mail.gmail.com.
>  
>
> >> For more options, visit https://groups.google.com/groups/opt_out. 
> >> 
> >> -- 
> >> 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 http://groups.google.com/group/django-users. 
> >> To view this discussion on the web visit 
> >> 
> https://groups.google.com/d/msgid/django-users/495305343-1386058174-cardhu_decombobulator_blackberry.rim.net-1176089190-%40b17.c3.bise7.blackberry.
>  
>
> >> For more options, visit https://groups.google.com/groups/opt_out. 
> > 
> > 
> > -- 
> > 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 http://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/CAHSNPWtJ80rqeDgJU4x3xk%2B3ABR1SKjA%2BohsPa3cPezx8O%3Darg%40mail.gmail.com.
>  
>
> > For more options, visit https://groups.google.com/groups/opt_out. 
>
>
>
> -- 
> MLHIM VIP Signup: http://goo.gl/22B0U 
>  
> Timothy Cook, MSc   +55 21 94711995 
> MLHIM http://www.mlhim.org 
> Like Us on FB: https://www.facebook.com/mlhim2 
> Circle us on G+: http://goo.gl/44EV5 
> Google Scholar: http://goo.gl/MMZ1o 
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook 
>

-- 
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 

Re: Save the user from one model to the another model

2013-12-03 Thread Timothy W. Cook
On Tue, Dec 3, 2013 at 9:56 AM, Aamu Padi  wrote:
> Ok! Plural names. Got it. But I was looking for something more of a
> overriding the save method for the Thread class, so that I don't have to do
> that in the view.
>

You can do it in the same view as the message.  You aren't limited to
working with only one model in a view.

HTH,
Tim




>
> On Tue, Dec 3, 2013 at 1:39 PM,  wrote:
>>
>> You're probably looking for something along the lines of:
>>
>> thread = Thread.objects.get(id=)
>> msg = Message.objects.get(id=)
>>
>> thread.user.add(msg.sender)
>>
>> Look at add() and remove() methods in documentation (search for related
>> managers).
>>
>> FYI - it's a good practice to name fields that use ManyToMany field in
>> plural, i.e. Thread.users would be better than Thread.user
>>
>> HTH
>>
>> Jirka
>> 
>> From: Aamu Padi 
>> Sender: django-users@googlegroups.com
>> Date: Tue, 3 Dec 2013 04:19:55 +0530
>> To: 
>> ReplyTo: django-users@googlegroups.com
>> Subject: Save the user from one model to the another model
>>
>> What I want to do is, whenever I create a new message, I want the sender
>> of the Message to be added to the user of the Thread. How do I do that?
>>
>>>
>>> class Thread(models.Model):
>>> user = models.ManyToManyField(User)
>>> is_hidden = models.ManyToManyField(User,
>>> related_name='hidden_thread', blank=True)
>>>
>>> def __unicode__(self):
>>> return unicode(self.id)
>>>
>>> class Message(models.Model):
>>> thread = models.ForeignKey(Thread)
>>> sent_date = models.DateTimeField(default=datetime.now)
>>> sender = models.ForeignKey(User)
>>> body = models.TextField()
>>> is_hidden = models.ManyToManyField(User,
>>> related_name='hidden_message', blank=True)
>>>
>>> def __unicode__(self):
>>> return "%s - %s" % (unicode(self.thread.id), self.body)
>>>
>> --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAHSNPWveL8rqDLenDLayGrtC_RAwQ-Pfp0SYravr7%2BuJzhBhXw%40mail.gmail.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>> --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/495305343-1386058174-cardhu_decombobulator_blackberry.rim.net-1176089190-%40b17.c3.bise7.blackberry.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHSNPWtJ80rqeDgJU4x3xk%2B3ABR1SKjA%2BohsPa3cPezx8O%3Darg%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.



-- 
MLHIM VIP Signup: http://goo.gl/22B0U

Timothy Cook, MSc   +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DOU3W2WyiGbRC4CZ_5_OYZiTWtrbcOrrH0M9dEXuGvSFJFzQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Save the user from one model to the another model

2013-12-03 Thread antialiasis
This seems like a job for 
signals. 
Register a post_save signal for the Message class, something like this:

from django.db.models.signals import post_save
from django.dispatch import receiver
from myapp.models import Message, Thread

@receiver(post_save, sender=Message)def add_to_thread(sender, instance, 
created, **kwargs):
if created:
instance.thread.user.add(instance.sender)



On Tuesday, December 3, 2013 11:56:23 AM UTC, Aamu Padi wrote:
>
> Ok! Plural names. Got it. But I was looking for something more of a 
> overriding the save method for the *Thread *class, so that I don't have 
> to do that in the view.
>
>
> On Tue, Dec 3, 2013 at 1:39 PM, wrote:
>
>> You're probably looking for something along the lines of:
>>
>> thread = Thread.objects.get(id=)
>> msg = Message.objects.get(id=)
>>
>> thread.user.add(msg.sender)
>>
>> Look at add() and remove() methods in documentation (search for related 
>> managers).
>>
>> FYI - it's a good practice to name fields that use ManyToMany field in 
>> plural, i.e. Thread.users would be better than Thread.user
>>
>> HTH
>>
>> Jirka
>> --
>> *From: * Aamu Padi  
>> *Sender: * django...@googlegroups.com  
>> *Date: *Tue, 3 Dec 2013 04:19:55 +0530
>> *To: *
>> *ReplyTo: * django...@googlegroups.com  
>> *Subject: *Save the user from one model to the another model
>>
>> What I want to do is, whenever I create a new message, I want the *sender 
>> *of the *Message* to be added to the *user *of the *Thread.* How do I do 
>> that?
>>  
>>
>>> class Thread(models.Model):
>>> user = models.ManyToManyField(User)
>>> is_hidden = models.ManyToManyField(User, 
>>> related_name='hidden_thread', blank=True)
>>>
>>> def __unicode__(self):
>>> return unicode(self.id)
>>>
>>> class Message(models.Model):
>>> thread = models.ForeignKey(Thread)
>>> sent_date = models.DateTimeField(default=datetime.now)
>>> sender = models.ForeignKey(User)
>>> body = models.TextField()
>>> is_hidden = models.ManyToManyField(User, 
>>> related_name='hidden_message', blank=True)
>>>
>>> def __unicode__(self):
>>> return "%s - %s" % (unicode(self.thread.id), self.body)
>>>
>>>  -- 
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAHSNPWveL8rqDLenDLayGrtC_RAwQ-Pfp0SYravr7%2BuJzhBhXw%40mail.gmail.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>> -- 
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/495305343-1386058174-cardhu_decombobulator_blackberry.rim.net-1176089190-%40b17.c3.bise7.blackberry
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/08020d00-75e3-4c5f-8a7b-76b5d4980740%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Save the user from one model to the another model

2013-12-03 Thread Aamu Padi
Ok! Plural names. Got it. But I was looking for something more of a
overriding the save method for the *Thread *class, so that I don't have to
do that in the view.


On Tue, Dec 3, 2013 at 1:39 PM,  wrote:

> You're probably looking for something along the lines of:
>
> thread = Thread.objects.get(id=)
> msg = Message.objects.get(id=)
>
> thread.user.add(msg.sender)
>
> Look at add() and remove() methods in documentation (search for related
> managers).
>
> FYI - it's a good practice to name fields that use ManyToMany field in
> plural, i.e. Thread.users would be better than Thread.user
>
> HTH
>
> Jirka
> --
> *From: * Aamu Padi 
> *Sender: * django-users@googlegroups.com
> *Date: *Tue, 3 Dec 2013 04:19:55 +0530
> *To: *
> *ReplyTo: * django-users@googlegroups.com
> *Subject: *Save the user from one model to the another model
>
> What I want to do is, whenever I create a new message, I want the *sender
> *of the *Message* to be added to the *user *of the *Thread.* How do I do
> that?
>
>
>> class Thread(models.Model):
>> user = models.ManyToManyField(User)
>> is_hidden = models.ManyToManyField(User,
>> related_name='hidden_thread', blank=True)
>>
>> def __unicode__(self):
>> return unicode(self.id)
>>
>> class Message(models.Model):
>> thread = models.ForeignKey(Thread)
>> sent_date = models.DateTimeField(default=datetime.now)
>> sender = models.ForeignKey(User)
>> body = models.TextField()
>> is_hidden = models.ManyToManyField(User,
>> related_name='hidden_message', blank=True)
>>
>> def __unicode__(self):
>> return "%s - %s" % (unicode(self.thread.id), self.body)
>>
>>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHSNPWveL8rqDLenDLayGrtC_RAwQ-Pfp0SYravr7%2BuJzhBhXw%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/495305343-1386058174-cardhu_decombobulator_blackberry.rim.net-1176089190-%40b17.c3.bise7.blackberry
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHSNPWtJ80rqeDgJU4x3xk%2B3ABR1SKjA%2BohsPa3cPezx8O%3Darg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Save the user from one model to the another model

2013-12-03 Thread jirka . vejrazka
You're probably looking for something along the lines of:

thread = Thread.objects.get(id=)
msg = Message.objects.get(id=)

thread.user.add(msg.sender)

Look at add() and remove() methods in documentation (search for related 
managers).

FYI - it's a good practice to name fields that use ManyToMany field in plural, 
i.e. Thread.users would be better than Thread.user

  HTH

Jirka

-Original Message-
From: Aamu Padi 
Sender: django-users@googlegroups.com
Date: Tue, 3 Dec 2013 04:19:55 
To: 
Reply-To: django-users@googlegroups.com
Subject: Save the user from one model to the another model

What I want to do is, whenever I create a new message, I want the *sender *of
the *Message* to be added to the *user *of the *Thread.* How do I do that?


> class Thread(models.Model):
> user = models.ManyToManyField(User)
> is_hidden = models.ManyToManyField(User, related_name='hidden_thread',
> blank=True)
>
> def __unicode__(self):
> return unicode(self.id)
>
> class Message(models.Model):
> thread = models.ForeignKey(Thread)
> sent_date = models.DateTimeField(default=datetime.now)
> sender = models.ForeignKey(User)
> body = models.TextField()
> is_hidden = models.ManyToManyField(User,
> related_name='hidden_message', blank=True)
>
> def __unicode__(self):
> return "%s - %s" % (unicode(self.thread.id), self.body)
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHSNPWveL8rqDLenDLayGrtC_RAwQ-Pfp0SYravr7%2BuJzhBhXw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/495305343-1386058174-cardhu_decombobulator_blackberry.rim.net-1176089190-%40b17.c3.bise7.blackberry.
For more options, visit https://groups.google.com/groups/opt_out.


Re: save form data to mysql table

2013-10-23 Thread Mahantesh U
Thanks a lot.. 

On Wednesday, October 23, 2013 5:46:05 PM UTC+5:30, Keith Edmiston wrote:
>
> I'm working on a similar learning opportunity as well and am having good 
> luck with www.tangowithdjango.com/book/
>
> Hopefully it will help you too. 
>
> Keith
>
> On Wednesday, October 23, 2013, Mahantesh U wrote:
>
>> Hi All,
>>
>>I ve a template base.html in project file. once the user enters data 
>> and clicks on submit button the details should save to mysql table  
>>
>> camp_db database. I dont ve idea of how to use ModelForm.
>>
>> How can i achieve this?
>>
>> pls help me soon.
>>
>> Thanks
>> Mahantesh
>>
>> -- 
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CANueA-8YJxBhd0QOtjAT51CYONff9NEnDFZh5CpEd%2B3S3H3G3g%40mail.gmail.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
> -- 
> Keith Edmiston
> (512)970-7222
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b0630b34-04f0-4694-9801-c1876a964f35%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: save form data to mysql table

2013-10-23 Thread Keith Edmiston
I'm working on a similar learning opportunity as well and am having good
luck with www.tangowithdjango.com/book/

Hopefully it will help you too.

Keith

On Wednesday, October 23, 2013, Mahantesh U wrote:

> Hi All,
>
>I ve a template base.html in project file. once the user enters data
> and clicks on submit button the details should save to mysql table
>
> camp_db database. I dont ve idea of how to use ModelForm.
>
> How can i achieve this?
>
> pls help me soon.
>
> Thanks
> Mahantesh
>
> --
> 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  'cvml', 'django-users%2bunsubscr...@googlegroups.com');>.
> To post to this group, send email to 
> django-users@googlegroups.com 'django-users@googlegroups.com');>
> .
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANueA-8YJxBhd0QOtjAT51CYONff9NEnDFZh5CpEd%2B3S3H3G3g%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>


-- 
Keith Edmiston
(512)970-7222

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAP_gv7%2BcwXffRVFR%3DAvbzXipNocrvoZqusKRo9bs3L3WLfDRnA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Save url containing special characters into mysql database using cursor object

2013-08-05 Thread Tom Evans
On Sat, Aug 3, 2013 at 8:04 PM, fanchyna  wrote:
>
>
>
> I am about to save the url below to my mysql database (innodb) using the
> cursor object:
>
>
> http://www-i6.informatik.rwth-aachen.de/publications/download/367/l{o}{o}fjonasbisanimaximiliangollanchrisianheigoldgeorghoffmeisterbj{o}rnplahlchristianschl{u}terralfneyhermann--the2006{rwth}parliamentaryspeechestranscriptionsystem--2006.pdf
>

What special characters are in that string?

> the insert statement is
>
> dbquery = "INSERT INTO maintable (url,state) VALUES (%s,%s)"
> dbqueryvalue = (url,'0')
>
> The cursor.execute(dbquery,dbqueryvalue)

So, not using django?

>
> error:
>
> _mysql_exceptions.Warning: Data truncated for column 'url' at row 1
>
> Other urls seem to be OK, but on this one cannot be saved.The url field
> can save up to 255 characters so the string length is not the problem.

That error message from mysql indicates that the data supplied is too
large for the column specified and has been truncated. Either your
table structure does not allow for 242 characters in that column, or
that's not the URL you are trying to insert. This WFM when I attempt
to reproduce your issue.

Cheers

Tom

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Save url containing special characters into mysql database using cursor object

2013-08-04 Thread gilberto dos santos alves
please see functions urllib.quote, urllib.quote_plus, urllib.urlencode on 
this manual python [1]

[1] http://docs.python.org/2/library/urllib.html#utility-functions

Em sábado, 3 de agosto de 2013 16h04min55s UTC-3, fanchyna escreveu:
>
> 
>   
> I am about to save the url below to my mysql database (innodb) using the 
> cursor object:
>
> http://www-i6.informatik.rwth-aachen.de/publications/download/367/l
> {o}{o}fjonasbisanimaximiliangollanchrisianheigoldgeorghoffmeisterbj{o}rnplahlchristianschl{u}terralfneyhermann--the2006{rwth}parliamentaryspeechestranscriptionsystem--2006.pdf
>
> the insert statement is
>
> dbquery = "INSERT INTO maintable (url,state) VALUES (%s,%s)"
> dbqueryvalue = (url,'0')
>
> The cursor.execute(dbquery,dbqueryvalue)
>
> error:
>
> _mysql_exceptions.Warning: Data truncated for column 'url' at row 1
>
> Other urls seem to be OK, but on this one cannot be saved.The url field 
> can save up to 255 characters so the string length is not the problem. 
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save data from html table

2013-07-16 Thread Bill Freeman
I presume that you mean an HTML table.

Didn't you already have to have the data in order to render the template?

Or are you using a template that someone else has rendered, that you have,
in python, as a string?  If this, then there are many libraries that can
parse a DOM for you.  If it is XHTML (legal XML) the lxml is a personal
favorite.  You can then extract the data as strings.  You will need to know
which field might be numbers and convert them yourself.  Similar for
booleans, etc.  The ORM might  help you with these last conversions.

Or are you updating a table in the browser, using some JavaScript that
allows the user to create rows and/or modify cells.  In that case I'd be
using jQuery to extract the values into JavaScript objects, and bundle them
as JSON to send to the view.  You still have type conversion, which you
could do on either the JavaScript or Python side.

Or are you doing something else entirely?


On Tue, Jul 16, 2013 at 9:07 AM, Randa Hisham  wrote:

> my problem not to save to database but is how to get data from template
>
>
> On Tue, Jul 16, 2013 at 3:03 PM, Lukas Nemec  wrote:
>
>>  That depends, you could use django.db models to access that table,
>> but that depends on the table - there is a ton of information on this
>> subject here:
>>
>> https://docs.djangoproject.com/en/dev/topics/db/models/
>>
>> Or, you could write a custom SQL that would fetch exactly the data you
>> want, and
>> save it in dict or list ... and you have this data inside view ...
>>
>>
>>
>> On 07/16/2013 03:00 PM, Randa Hisham wrote:
>>
>> if i have dynami table in my template contain data
>> wht is the best way to save this data from table to view
>>
>>  --
>> Randa Hesham
>> Software Developer
>>
>> Twitter:@ro0oraa 
>> FaceBook:Randa Hisham 
>>
>> ٍ
>>   --
>> 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 http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>>
>>  --
>> 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 http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
>
> --
> Randa Hesham
> Software Developer
>
> Twitter:@ro0oraa 
> FaceBook:Randa Hisham 
>
> ٍ
>
> --
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save data from html table

2013-07-16 Thread Lukas Nemec
Alright, so you have some rendered table in template, and you want to 
get it back to view?

That is the other way around I'm afraid...

request
   |
DB -> model ->   urlconf - > view -> template -> response

this is how the django responds to request ...
so any data you want to have in view, you have to create in view

another way - but that is kind of a hack - is to render a template and 
send it
with redirect to another url where you can parse it in another view, but 
this is

super ugly, and don't know if it would work..

I'm sorry but I don't have enough information to tell you more ...

On 07/16/2013 03:07 PM, Randa Hisham wrote:

my problem not to save to database but is how to get data from template


On Tue, Jul 16, 2013 at 3:03 PM, Lukas Nemec > wrote:


That depends, you could use django.db models to access that table,
but that depends on the table - there is a ton of information on
this subject here:

https://docs.djangoproject.com/en/dev/topics/db/models/

Or, you could write a custom SQL that would fetch exactly the data
you want, and
save it in dict or list ... and you have this data inside view ...



On 07/16/2013 03:00 PM, Randa Hisham wrote:

if i have dynami table in my template contain data
wht is the best way to save this data from table to view

-- 
Randa Hesham

Software Developer

Twitter:@ro0oraa 
FaceBook:Randa Hisham 

ٍ
-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.





--
Randa Hesham
Software Developer

Twitter:@ro0oraa 
FaceBook:Randa Hisham 

ٍ
--
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




--
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save data from html table

2013-07-16 Thread Randa Hisham
my problem not to save to database but is how to get data from template


On Tue, Jul 16, 2013 at 3:03 PM, Lukas Nemec  wrote:

>  That depends, you could use django.db models to access that table,
> but that depends on the table - there is a ton of information on this
> subject here:
>
> https://docs.djangoproject.com/en/dev/topics/db/models/
>
> Or, you could write a custom SQL that would fetch exactly the data you
> want, and
> save it in dict or list ... and you have this data inside view ...
>
>
>
> On 07/16/2013 03:00 PM, Randa Hisham wrote:
>
> if i have dynami table in my template contain data
> wht is the best way to save this data from table to view
>
>  --
> Randa Hesham
> Software Developer
>
> Twitter:@ro0oraa 
> FaceBook:Randa Hisham 
>
> ٍ
>   --
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
>  --
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Randa Hesham
Software Developer

Twitter:@ro0oraa 
FaceBook:Randa Hisham 

ٍ

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save data from html table

2013-07-16 Thread Lukas Nemec

That depends, you could use django.db models to access that table,
but that depends on the table - there is a ton of information on this 
subject here:


https://docs.djangoproject.com/en/dev/topics/db/models/

Or, you could write a custom SQL that would fetch exactly the data you 
want, and

save it in dict or list ... and you have this data inside view ...


On 07/16/2013 03:00 PM, Randa Hisham wrote:

if i have dynami table in my template contain data
wht is the best way to save this data from table to view

--
Randa Hesham
Software Developer

Twitter:@ro0oraa 
FaceBook:Randa Hisham 

ٍ
--
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




--
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Save String /Value to Table Entry

2013-06-27 Thread Bill Freeman
There are several approaches:

1. Your code that currently reads the string could connect to the Django
site via HTTP, log in as a user to which you have given suitable
permissions, and know enough about how to talk to the admin interface to
create and populate instances of the model that you have designed to hold
the strings.

2. Similar to 1, but using a custom view you have written (possibly
RESTful) that is single purpose for creating the populated model instances,
and designed to be easier for a program to talk to.

3. Your program could create a Django "fixture" file containing the
information, which can then be loaded using manage.py loaddata to load it
into Django.  See https://docs.djangoproject.com/en/1.5/howto/initial-data/

4. Assuming that your existing code is in python, write a new management
command based on it that fetches your strings as now, and then directly
saves them using the ORM.

5. Have your program use an independent connection to the database that is
backing Django to create the rows directly.

I suspect that 3 or 4 are the simplest to code, but will require more
Django study than that required to put up a web site.

Bill


On Wed, Jun 26, 2013 at 5:28 PM, hiQ  wrote:

> I currently use Microsoft Visual Studio 2010 Express *(my hardware is
> working under Windows)* and have created an application that can read
> strings from an external source and display them on Msgbox's.
>
> I would like to save these values into an table in django so I can query
> them later. Is this possible. May I ask for some tutorial references or
> guidance?
>
> Thanks,
>
> --
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save data using checkbox click an input

2013-06-03 Thread roopasingh250
Hi,

  I agree that the logic is duplicated, I corrected in views.

  I used that line to render the parent element and below the corresponding 
parent element their respective child element should come to display.That 
logic worked for me.I am updating my new template here,the view code is 
same,now the problem is i am able to save the last parent element's child 
element only.If more than 1 parent element and their child element is 
their,i can save the last parent element's child element data only ,rest of 
them if i check and click save it is not save in database.

updated template is

 {% for type in typeList%}
   {% if type.parent_type_id == None %}
   {{type.title}}
   {% else %}
   {{ type.title 
}} 
   {% endif %}
 {% endfor %}

Can any one help me in achieving.

Thanks

On Saturday, June 1, 2013 5:50:57 PM UTC+5:30, roopas...@gmail.com wrote:
>
> Hi,i am using django developing an app.Problem i am facing is i queried a 
> list of data from one table and save the same data to another table,but the 
> condition is if the user clicks the checkbox and press save.If the checkbox 
> is clicked the value(label) of the checkbox should save in database,this is 
> my requirement in user level(i explained).I tried with the below code ,
>
> views.py
>
> def what(request):
> typeList = Types.objects.filter(user=user, 
> is_active=True,parent_type_id=None)
> list = []
> for type in typeList:
> if not type.parent_type_id:
> list.append(type)
> subtype = Types.objects.filter(parent_type_id=type.id, 
> is_active=True)
> for subtypes in subtype:
> list.append(subtypes)
> if request.method == 'POST':
> ReportType.objects.filter(report=report).delete()
> checked_ones = [unicode(x) for x in subtype if unicode(x) in 
> request.POST.keys()]
> for entry in checked_ones:
> r = ReportType()
> r.report = report 
> r.title = entry
> r.save()
> return redirect('/member/where/')
> checked_ones = [x.title for x in 
> ReportType.objects.filter(report=report)]  
> return render(request, 'incident/what.html',{''typeList':list,'})
>
> template is
> 
>  {% csrf_token %}
> {% for type in typeList%}
>  {% if type.parent_type_id == None %}
>{{type.title}}
>{% else %}
>{{type.title}}
>   {% endif %}
> {% endfor %}
> 
>
> See,i posted all my code to better understand.
>
> Let me tell you the problem i am facing.
>
> 1.I am not able to save the data to database,i believe that my view is 
> ok,might be some problem with template.
>
> Please help me in do this.
>
> Thanks
> 
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save data using checkbox click an input

2013-06-01 Thread Artem Zinoviev
How you send your form? Checkbox don`t send your form... Why 
you duplicate logic  in views and template? ( 
for type in typeList:
  if not type.parent_type_id: 
***
&& 
 {% for type in typeList%}
  {% if type.parent_type_id == None %} ).
***

P.S. All this code is incorrect. it can`t work.
This is must be here - 

суббота, 1 июня 2013 г., 15:20:57 UTC+3 пользователь roopas...@gmail.com 
написал:
>
> Hi,i am using django developing an app.Problem i am facing is i queried a 
> list of data from one table and save the same data to another table,but the 
> condition is if the user clicks the checkbox and press save.If the checkbox 
> is clicked the value(label) of the checkbox should save in database,this is 
> my requirement in user level(i explained).I tried with the below code ,
>
> views.py
>
> def what(request):
> typeList = Types.objects.filter(user=user, 
> is_active=True,parent_type_id=None)
> list = []
> for type in typeList:
> if not type.parent_type_id:
> list.append(type)
> subtype = Types.objects.filter(parent_type_id=type.id, 
> is_active=True)
> for subtypes in subtype:
> list.append(subtypes)
> if request.method == 'POST':
> ReportType.objects.filter(report=report).delete()
> checked_ones = [unicode(x) for x in subtype if unicode(x) in 
> request.POST.keys()]
> for entry in checked_ones:
> r = ReportType()
> r.report = report 
> r.title = entry
> r.save()
> return redirect('/member/where/')
> checked_ones = [x.title for x in 
> ReportType.objects.filter(report=report)]  
> return render(request, 'incident/what.html',{''typeList':list,'})
>
> template is
> 
>  {% csrf_token %}
> {% for type in typeList%}
>  {% if type.parent_type_id == None %}
>{{type.title}}
>{% else %}
>{{type.title}}
>   {% endif %}
> {% endfor %}
> 
>
> See,i posted all my code to better understand.
>
> Let me tell you the problem i am facing.
>
> 1.I am not able to save the data to database,i believe that my view is 
> ok,might be some problem with template.
>
> Please help me in do this.
>
> Thanks
> 
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-26 Thread Larry Martell
On Tue, Mar 26, 2013 at 6:48 AM, Larry Martell  wrote:
> On Wed, Mar 20, 2013 at 6:26 PM, Felipe Coelho  wrote:
>>> 2013/3/20 Larry Martell 
>>>
>>>
>>> I'm not outputting any PDF. I have a zip file I want to download to
>>> the user's computer, and I also want my template rendered.
>>
>>
>> That means you have should have two requests, possibly processed by two
>> different views, which is what Felipe (the other one) is trying to tell you.
>>
>> You must have a view that renders your template. In the resulting page,
>> include something to trigger the file download from the other view.
>
> OK, I've implemented this using ajax as the other Felipe suggested,
> but the save as is not getting triggered on the response from the view
> invoked by the ajax call. If I invoke the same view by cutting and
> pasting the URL generated by the ajax call into my browser's address
> bar the save as is invoked, but when called from ajax it is not. Any
> idea why that could be happening?

I figured this out - instead of using ajax I just assign the URL to
location.href. Works perfectly.

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-26 Thread Larry Martell
On Wed, Mar 20, 2013 at 6:26 PM, Felipe Coelho  wrote:
>> 2013/3/20 Larry Martell 
>>
>>
>> I'm not outputting any PDF. I have a zip file I want to download to
>> the user's computer, and I also want my template rendered.
>
>
> That means you have should have two requests, possibly processed by two
> different views, which is what Felipe (the other one) is trying to tell you.
>
> You must have a view that renders your template. In the resulting page,
> include something to trigger the file download from the other view.

OK, I've implemented this using ajax as the other Felipe suggested,
but the save as is not getting triggered on the response from the view
invoked by the ajax call. If I invoke the same view by cutting and
pasting the URL generated by the ajax call into my browser's address
bar the save as is invoked, but when called from ajax it is not. Any
idea why that could be happening?

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-20 Thread Felipe Coelho
>
> 2013/3/20 Larry Martell 


> I'm not outputting any PDF. I have a zip file I want to download to
> the user's computer, and I also want my template rendered.


That means you have should have two requests, possibly processed by two
different views, which is what Felipe (the other one) is trying to tell you.

You must have a view that renders your template. In the resulting page,
include something to trigger the file
downloadfrom
the other view.

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-20 Thread Larry Martell
On Wed, Mar 20, 2013 at 3:01 PM, Felipe Prenholato  wrote:
> I mean, you output PDF.
> It's a simple view that output PDF, this view is called via ajax after page
> that show HTML loads.

I'm not outputting any PDF. I have a zip file I want to download to
the user's computer, and I also want my template rendered.


> 2013/3/20 Larry Martell 
>>
>> On Wed, Mar 20, 2013 at 2:27 PM, Felipe Prenholato 
>> wrote:
>> > When page loads (document.ready), do a ajax call to a view that returns
>> > PDF
>> > file.
>>
>> How is a PDF file involved here?
>>
>>
>> > 2013/3/20 Larry Martell 
>> >>
>> >> On Wed, Mar 20, 2013 at 5:34 AM, Tom Evans 
>> >> wrote:
>> >> > On Wed, Mar 20, 2013 at 11:28 AM, Larry Martell
>> >> >  wrote:
>> >> >> Yes, I have convinced them to not require this. Now my issue is how
>> >> >> to
>> >> >> cause a file to be saved and to also render a template. When I
>> >> >> return
>> >> >> this:
>> >> >>
>> >> >> response = HttpResponse('This is what I want to save')
>> >> >> response['Content-Type'] = 'application/gzip'
>> >> >> response['Content-disposition'] = 'Attachment;
>> >> >> filename=export.gzip'
>> >> >> return response
>> >> >>
>> >> >> my template is obviously not rendered. How can I do this and also
>> >> >> render my template at the same time?
>> >> >>
>> >> >
>> >> > Use render() shortcut to generate a response and set the appropriate
>> >> > attributes on it before returning the response. Eg:
>> >> >
>> >> >   response = render(request, 'my_template.html', { })
>> >> >   response['Content-Type'] = 'application/gzip'
>> >> >   response['Content-disposition'] = 'Attachment;
>> >> > filename=export.gzip'
>> >> >   return response
>> >>
>> >> This is downloading a file, but the file that gets downloaded is not
>> >> export.gzip, but instead is a copy of my rendered template and my
>> >> template is not rendered in my browser.
>> >>
>> >> --
>> >> 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 http://groups.google.com/group/django-users?hl=en.
>> >> For more options, visit https://groups.google.com/groups/opt_out.
>> >>
>> >>
>> >
>> > --
>> > 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 http://groups.google.com/group/django-users?hl=en.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>>
>> --
>> 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 http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
> --
> 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 http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-20 Thread Felipe Prenholato
I mean, you output PDF.
It's a simple view that output PDF, this view is called via ajax after page
that show HTML loads.

Felipe 'chronos' Prenholato.
Linux User nº 405489
Home page: http://devwithpassion.com | http://chronosbox.org/blog
GitHub: http://github.com/chronossc/ | Twitter: http://twitter.com/chronossc


2013/3/20 Larry Martell 

> On Wed, Mar 20, 2013 at 2:27 PM, Felipe Prenholato 
> wrote:
> > When page loads (document.ready), do a ajax call to a view that returns
> PDF
> > file.
>
> How is a PDF file involved here?
>
>
> > 2013/3/20 Larry Martell 
> >>
> >> On Wed, Mar 20, 2013 at 5:34 AM, Tom Evans 
> >> wrote:
> >> > On Wed, Mar 20, 2013 at 11:28 AM, Larry Martell
> >> >  wrote:
> >> >> Yes, I have convinced them to not require this. Now my issue is how
> to
> >> >> cause a file to be saved and to also render a template. When I return
> >> >> this:
> >> >>
> >> >> response = HttpResponse('This is what I want to save')
> >> >> response['Content-Type'] = 'application/gzip'
> >> >> response['Content-disposition'] = 'Attachment;
> >> >> filename=export.gzip'
> >> >> return response
> >> >>
> >> >> my template is obviously not rendered. How can I do this and also
> >> >> render my template at the same time?
> >> >>
> >> >
> >> > Use render() shortcut to generate a response and set the appropriate
> >> > attributes on it before returning the response. Eg:
> >> >
> >> >   response = render(request, 'my_template.html', { })
> >> >   response['Content-Type'] = 'application/gzip'
> >> >   response['Content-disposition'] = 'Attachment; filename=export.gzip'
> >> >   return response
> >>
> >> This is downloading a file, but the file that gets downloaded is not
> >> export.gzip, but instead is a copy of my rendered template and my
> >> template is not rendered in my browser.
> >>
> >> --
> >> 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 http://groups.google.com/group/django-users?hl=en.
> >> For more options, visit https://groups.google.com/groups/opt_out.
> >>
> >>
> >
> > --
> > 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 http://groups.google.com/group/django-users?hl=en.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
>
> --
> 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 http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-20 Thread Larry Martell
On Wed, Mar 20, 2013 at 2:27 PM, Felipe Prenholato  wrote:
> When page loads (document.ready), do a ajax call to a view that returns PDF
> file.

How is a PDF file involved here?


> 2013/3/20 Larry Martell 
>>
>> On Wed, Mar 20, 2013 at 5:34 AM, Tom Evans 
>> wrote:
>> > On Wed, Mar 20, 2013 at 11:28 AM, Larry Martell
>> >  wrote:
>> >> Yes, I have convinced them to not require this. Now my issue is how to
>> >> cause a file to be saved and to also render a template. When I return
>> >> this:
>> >>
>> >> response = HttpResponse('This is what I want to save')
>> >> response['Content-Type'] = 'application/gzip'
>> >> response['Content-disposition'] = 'Attachment;
>> >> filename=export.gzip'
>> >> return response
>> >>
>> >> my template is obviously not rendered. How can I do this and also
>> >> render my template at the same time?
>> >>
>> >
>> > Use render() shortcut to generate a response and set the appropriate
>> > attributes on it before returning the response. Eg:
>> >
>> >   response = render(request, 'my_template.html', { })
>> >   response['Content-Type'] = 'application/gzip'
>> >   response['Content-disposition'] = 'Attachment; filename=export.gzip'
>> >   return response
>>
>> This is downloading a file, but the file that gets downloaded is not
>> export.gzip, but instead is a copy of my rendered template and my
>> template is not rendered in my browser.
>>
>> --
>> 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 http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
> --
> 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 http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-20 Thread Felipe Prenholato
When page loads (document.ready), do a ajax call to a view that returns PDF
file.

Felipe 'chronos' Prenholato.
Linux User nº 405489
Home page: http://devwithpassion.com | http://chronosbox.org/blog
GitHub: http://github.com/chronossc/ | Twitter: http://twitter.com/chronossc


2013/3/20 Larry Martell 

> On Wed, Mar 20, 2013 at 5:34 AM, Tom Evans 
> wrote:
> > On Wed, Mar 20, 2013 at 11:28 AM, Larry Martell 
> wrote:
> >> Yes, I have convinced them to not require this. Now my issue is how to
> >> cause a file to be saved and to also render a template. When I return
> >> this:
> >>
> >> response = HttpResponse('This is what I want to save')
> >> response['Content-Type'] = 'application/gzip'
> >> response['Content-disposition'] = 'Attachment;
> filename=export.gzip'
> >> return response
> >>
> >> my template is obviously not rendered. How can I do this and also
> >> render my template at the same time?
> >>
> >
> > Use render() shortcut to generate a response and set the appropriate
> > attributes on it before returning the response. Eg:
> >
> >   response = render(request, 'my_template.html', { })
> >   response['Content-Type'] = 'application/gzip'
> >   response['Content-disposition'] = 'Attachment; filename=export.gzip'
> >   return response
>
> This is downloading a file, but the file that gets downloaded is not
> export.gzip, but instead is a copy of my rendered template and my
> template is not rendered in my browser.
>
> --
> 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 http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-20 Thread Larry Martell
On Wed, Mar 20, 2013 at 5:34 AM, Tom Evans  wrote:
> On Wed, Mar 20, 2013 at 11:28 AM, Larry Martell  
> wrote:
>> Yes, I have convinced them to not require this. Now my issue is how to
>> cause a file to be saved and to also render a template. When I return
>> this:
>>
>> response = HttpResponse('This is what I want to save')
>> response['Content-Type'] = 'application/gzip'
>> response['Content-disposition'] = 'Attachment; filename=export.gzip'
>> return response
>>
>> my template is obviously not rendered. How can I do this and also
>> render my template at the same time?
>>
>
> Use render() shortcut to generate a response and set the appropriate
> attributes on it before returning the response. Eg:
>
>   response = render(request, 'my_template.html', { })
>   response['Content-Type'] = 'application/gzip'
>   response['Content-disposition'] = 'Attachment; filename=export.gzip'
>   return response

This is downloading a file, but the file that gets downloaded is not
export.gzip, but instead is a copy of my rendered template and my
template is not rendered in my browser.

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-20 Thread Tom Evans
On Wed, Mar 20, 2013 at 11:28 AM, Larry Martell  wrote:
> Yes, I have convinced them to not require this. Now my issue is how to
> cause a file to be saved and to also render a template. When I return
> this:
>
> response = HttpResponse('This is what I want to save')
> response['Content-Type'] = 'application/gzip'
> response['Content-disposition'] = 'Attachment; filename=export.gzip'
> return response
>
> my template is obviously not rendered. How can I do this and also
> render my template at the same time?
>

Use render() shortcut to generate a response and set the appropriate
attributes on it before returning the response. Eg:

  response = render(request, 'my_template.html', { })
  response['Content-Type'] = 'application/gzip'
  response['Content-disposition'] = 'Attachment; filename=export.gzip'
  return response

Cheers

Tom

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-20 Thread Larry Martell
On Wed, Mar 20, 2013 at 2:50 AM, Branko Majic  wrote:
> On Tue, 19 Mar 2013 19:27:33 -0600
> Larry Martell  wrote:
>
>> On Tue, Mar 19, 2013 at 7:07 PM, Tim Chase
>>  wrote:
>> > On 2013-03-19 18:42, Larry Martell wrote:
>> >> https://docs.djangoproject.com/en/dev/howto/outputting-pdf/ which
>> >> says to use the Content-disposition header to trigger the save as.
>> >> I've done this, but I don't get a save as dialog box. The file is
>> >> just downloaded to a download dir with the name I have provided.
>> >>
>> >> Is there a way I can specify from my app what directory I want the
>> >> file saved to?
>> >
>> > I believe this is a browser-configuration setting controlled by the
>> > user, not by HTTP metadata.  In Firefox, I have the option to either
>> > open the file or save the file, along with a check-box to "always do
>> > this"; FF also provides me the control to specify where the file
>> > goes on a per-download basis, or to default to a given location.
>> >
>> > tl;dr: I don't think your web-app can take away this control from
>> > the user.
>>
>> That's what I thought, but my client wants the file saved to a
>> specific location. This is an internal app, not something for public
>> usage. Perhaps I can pass the file back in a context and save it from
>> javscript.
>>
>
> I'd be very surprised if you could use JavaScript to do something like
> that. It would've been considered a security vulnerability by any
> browser software vendor out there.
>
> If client wants the file to be saved to specific location, you should
> probably try to direct them to some specific solution for the browser
> of their choice. For Firefox you should be able to find some extensions
> that can automatically save files to certain directories based on file
> type. Maybe there's something out there that could do so based on MIME
> type (Content-Disposition) set for the file (so you can set something
> other than PDF for it in order to have other website PDFs saved to
> other locations).
>
> If you are really persistent, you could try using some kind of Flash
> thing or Java applet, but that's a very, very, very, very bad idea.
>
> So, you'll probably left with negotiating it with your client not to
> insist on that, or see if you can tweak the browser settings in some
> way (most probably with an extension) :)

Yes, I have convinced them to not require this. Now my issue is how to
cause a file to be saved and to also render a template. When I return
this:

response = HttpResponse('This is what I want to save')
response['Content-Type'] = 'application/gzip'
response['Content-disposition'] = 'Attachment; filename=export.gzip'
return response

my template is obviously not rendered. How can I do this and also
render my template at the same time?

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-20 Thread Branko Majic
On Tue, 19 Mar 2013 19:27:33 -0600
Larry Martell  wrote:

> On Tue, Mar 19, 2013 at 7:07 PM, Tim Chase
>  wrote:
> > On 2013-03-19 18:42, Larry Martell wrote:
> >> https://docs.djangoproject.com/en/dev/howto/outputting-pdf/ which
> >> says to use the Content-disposition header to trigger the save as.
> >> I've done this, but I don't get a save as dialog box. The file is
> >> just downloaded to a download dir with the name I have provided.
> >>
> >> Is there a way I can specify from my app what directory I want the
> >> file saved to?
> >
> > I believe this is a browser-configuration setting controlled by the
> > user, not by HTTP metadata.  In Firefox, I have the option to either
> > open the file or save the file, along with a check-box to "always do
> > this"; FF also provides me the control to specify where the file
> > goes on a per-download basis, or to default to a given location.
> >
> > tl;dr: I don't think your web-app can take away this control from
> > the user.
> 
> That's what I thought, but my client wants the file saved to a
> specific location. This is an internal app, not something for public
> usage. Perhaps I can pass the file back in a context and save it from
> javscript.
> 

I'd be very surprised if you could use JavaScript to do something like
that. It would've been considered a security vulnerability by any
browser software vendor out there.

If client wants the file to be saved to specific location, you should
probably try to direct them to some specific solution for the browser
of their choice. For Firefox you should be able to find some extensions
that can automatically save files to certain directories based on file
type. Maybe there's something out there that could do so based on MIME
type (Content-Disposition) set for the file (so you can set something
other than PDF for it in order to have other website PDFs saved to
other locations).

If you are really persistent, you could try using some kind of Flash
thing or Java applet, but that's a very, very, very, very bad idea.

So, you'll probably left with negotiating it with your client not to
insist on that, or see if you can tweak the browser settings in some
way (most probably with an extension) :)

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.


signature.asc
Description: PGP signature


Re: save as

2013-03-19 Thread Larry Martell
On Tue, Mar 19, 2013 at 7:07 PM, Tim Chase
 wrote:
> On 2013-03-19 18:42, Larry Martell wrote:
>> https://docs.djangoproject.com/en/dev/howto/outputting-pdf/ which
>> says to use the Content-disposition header to trigger the save as.
>> I've done this, but I don't get a save as dialog box. The file is
>> just downloaded to a download dir with the name I have provided.
>>
>> Is there a way I can specify from my app what directory I want the
>> file saved to?
>
> I believe this is a browser-configuration setting controlled by the
> user, not by HTTP metadata.  In Firefox, I have the option to either
> open the file or save the file, along with a check-box to "always do
> this"; FF also provides me the control to specify where the file goes
> on a per-download basis, or to default to a given location.
>
> tl;dr: I don't think your web-app can take away this control from the
> user.

That's what I thought, but my client wants the file saved to a
specific location. This is an internal app, not something for public
usage. Perhaps I can pass the file back in a context and save it from
javscript.

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: save as

2013-03-19 Thread Tim Chase
On 2013-03-19 18:42, Larry Martell wrote:
> https://docs.djangoproject.com/en/dev/howto/outputting-pdf/ which
> says to use the Content-disposition header to trigger the save as.
> I've done this, but I don't get a save as dialog box. The file is
> just downloaded to a download dir with the name I have provided.
> 
> Is there a way I can specify from my app what directory I want the
> file saved to?

I believe this is a browser-configuration setting controlled by the
user, not by HTTP metadata.  In Firefox, I have the option to either
open the file or save the file, along with a check-box to "always do
this"; FF also provides me the control to specify where the file goes
on a per-download basis, or to default to a given location.

tl;dr: I don't think your web-app can take away this control from the
user.

-tkc


-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Save formtools.WizardView for later completion in another session?

2012-10-26 Thread ducky
I also came across this issue. I managed to address this by actually 
looking at the code for django.contrib.formtools.wizard.views.WizardView. 

(I am no django expert. So I am sure there might be a cleaner way. This 
worked for me. So I am just sharing my experience.)

I overrode the get and render_done method of SessionWizardView. The session 
data is saved in a dictionary called storage.data. It is initialized in the 
get method and destroyed in render_done method. 

So I created a model in my database to hold: an id and a text field which 
holds the json version of storage.data.

To save the session data, place a hook in render_done method to save the 
data to the model and generate an id.

To restore the session, pass the id as a parameter to the form wizard. I've 
put some sample code here: https://gist.github.com/3959900

Cheers


On Tuesday, 2 October 2012 16:26:57 UTC+1, Alex S-B. wrote:
>
> I have a long multi-page form wizard (a 
> django.contrib.formtools.wizard.views.SessionWizardView) that I would like 
> the user to be able to continue working through even after logging out and 
> back in from a different computer. That is, I would like the wizard data to 
> persist across sessions until completed. Are there any examples of how to 
> do this? Is this best approach to write my own custom storage backend?
>
> Thanks!
> Alex
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/jBXw6R8knNgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save() got an unexpected keyword argument 'force_insert'

2012-09-25 Thread Dan Gentry
To address the original question, I saw a similar error when overriding the 
save() function of a model.  The solution was to include *args and **kwargs 
in the function definition:

def save(self,*args, **kwargs):
# your custom code here #
super(MyModel, self).save(*args, **kwargs)


>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/vYCgvZ74BEQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save() got an unexpected keyword argument 'force_insert'

2012-09-24 Thread Joel Goldstick
On Mon, Sep 24, 2012 at 12:51 AM, Laxmikant Gurnalkar
 wrote:
>
> Hi guys,
> Anybody knows why I'm at this stage ?
> Group.objects.using('db2').get_or_create(name='Maintenance Admin')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line
> 383, in get_or_create
> obj.save(force_insert=True, using=self.db)
> TypeError: save() got an unexpected keyword argument 'force_insert'
>
>
> I'm getting this error on creating a new group on mydatabase2
> Not getting the exact reason behind this ...
> plz help ...
>
> Thanks in Advance
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/4Rosfupipe4J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

This is the first google entry for your error message:

https://code.djangoproject.com/ticket/8662

It looks like the docs were wrong, but they have been fixed.

-- 
Joel Goldstick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save Tweepy tweets in database

2012-05-08 Thread Aziz Bookwala
Hey

You can go through the Django basic
documentationon
views. It should answer most of your questions.

On Tue, May 8, 2012 at 4:43 PM, coded kid  wrote:

> creating the model is not a problem but the problem is how to make use of
> it in views.py. You have any idea?
>
>
> On Tuesday, 8 May 2012 11:19:27 UTC+1, coded kid wrote:
>>
>> I want to save users tweets in my db (MySQL) But I'm finding it
>> difficult to get how I will go about it. The main problem is that, I
>> didn't create any models for it, I just input the below codes in my
>> views,since I'm getting users tweets through tweepy api.
>>
>> The question now is, how will I save users tweets in my Database?
>>
>> Kindly give me a reply if you know how I will solve this problem!
>> Thanks.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/xhk_1kmqwVwJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
- Aziz M. Bookwala

Website  | Twitter  |
Github 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save Tweepy tweets in database

2012-05-08 Thread coded kid
creating the model is not a problem but the problem is how to make use of 
it in views.py. You have any idea?

On Tuesday, 8 May 2012 11:19:27 UTC+1, coded kid wrote:
>
> I want to save users tweets in my db (MySQL) But I'm finding it 
> difficult to get how I will go about it. The main problem is that, I 
> didn't create any models for it, I just input the below codes in my 
> views,since I'm getting users tweets through tweepy api. 
>
> The question now is, how will I save users tweets in my Database? 
>
> Kindly give me a reply if you know how I will solve this problem! 
> Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/xhk_1kmqwVwJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save Tweepy tweets in database

2012-05-08 Thread kenneth gonsalves
On Tue, 2012-05-08 at 03:19 -0700, coded kid wrote:
> I want to save users tweets in my db (MySQL) But I'm finding it
> difficult to get how I will go about it. The main problem is that, I
> didn't create any models for it, I just input the below codes in my
> views,since I'm getting users tweets through tweepy api.
> 
> The question now is, how will I save users tweets in my Database?
> 
> Kindly give me a reply if you know how I will solve this problem!
> Thanks. 

make a model to hold the tweets and save.
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save() creates new entry instead of updating the passed on as instance

2012-03-12 Thread Peter of the Norse
There are some issues with the code.
First, entry.id = entry_id is redundant. It might even be the cause of the new 
Entry.
https://docs.djangoproject.com/en/dev/ref/models/instances/#how-django-knows-to-update-vs-insert
Second, the best way to update from a form and code at the same time is to do 
save(commit=False). Updating your code:
form = EntryForm(data=request.POST, instance=entry)
if form.is_valid():
  updated_entry = form.save(commit=False)
  updated_entry.owner = request.user
  updated_entry.save()
  return redirect('entry')


On Mar 10, 2012, at 7:48 PM, Zeengr wrote:

> this is my code and weirdly it creates new entry instead of updating the 
> passed one in instance argument, don't know if that because of m2m 
> relationship in Entry model or my code is broken!
> what could be the cause?
> 
> ### my edit view
> @login_required
> def edit_entry_view(request, entry_id):
> 
> try:
> entry = Entry.objects.get(pk=entry_id, is_visible=True)
> except ObjectDoesNotExist:
> return render(request, 'entry/entry.html', {'no_enties': True})
> 
> if request.method == 'POST':
> entry.owner = request.user
> entry.id = entry_id
> form = EntryForm(data=request.POST, instance=entry)
> if form.is_valid():
>   form.save()
>   return redirect('entry')
> else:
> form = EntryForm(instance=entry)
> return render(request, 'entry/edit_entry.html', {'form': form})
> 
> ###my form
> class EntryForm(ModelForm):
> 
> class Meta:
> model = Entry
> exclude = ('owner')
> 
>  
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/MQ8mh7qDPHYJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

Peter of the Norse
rahmc...@radio1190.org



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save out a test database?

2011-06-04 Thread Margie Roginski
At the time I asked the question I just had the sense that I wanted to
debug an issue by bringing up the web interface midway through my
test.   I attempted to do things like stop midway through the test via
set_trace() and then ctrl-c, then look at the db from a runserver run
that was pointing to the test database, but I find that the test
database is empty, as if the data has not yet been written out to it
by the test.

Perhaps if I call dumpdata from the call_command as you suggest, that
will get around this.

Maybe I don't even need this.  It just seemed nice to be able to debug
a test from the web interface, but in reality, now that I am off and
running writing tests, I guess I haven't ended up needing it after
all ...

In any case, thanks for your response.

Margie

On Jun 4, 5:47 am, Karen Tracey  wrote:
> On Thu, Jun 2, 2011 at 10:04 AM, Margie Roginski
> wrote:
>
> > Karen Tracy, if you are reading this, could you comment?
>
> > As the person that seems to be most knowledgable about django testing
> > (your Django 1.1 Testing book is fantastic - I highly recommend it!),
> > can you confirm that something like this is the best way to go?  It
> > seems strange to me that there is no more standard way of dumping the
> > database from inside a test so that the state can be replicated for
> > use in a runserver environment.
>
> Well, usually you want to go the other way: ensure your test run replicates
> your real running environment. I'm a little unclear on why you want to save
> the DB state from during a test?
>
> Probably  easier than using serialize directly, particularly if you want the
> whole DB, would be to call the dumpdata command via 
> call_command:https://docs.djangoproject.com/en/1.3/ref/django-admin/#running-manag...
>
> Karen
> --http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save out a test database?

2011-06-04 Thread Karen Tracey
On Thu, Jun 2, 2011 at 10:04 AM, Margie Roginski
wrote:

> Karen Tracy, if you are reading this, could you comment?
>
> As the person that seems to be most knowledgable about django testing
> (your Django 1.1 Testing book is fantastic - I highly recommend it!),
> can you confirm that something like this is the best way to go?  It
> seems strange to me that there is no more standard way of dumping the
> database from inside a test so that the state can be replicated for
> use in a runserver environment.
>
>
Well, usually you want to go the other way: ensure your test run replicates
your real running environment. I'm a little unclear on why you want to save
the DB state from during a test?

Probably  easier than using serialize directly, particularly if you want the
whole DB, would be to call the dumpdata command via call_command:
https://docs.djangoproject.com/en/1.3/ref/django-admin/#running-management-commands-from-your-code

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save out a test database?

2011-06-03 Thread Steve Bywater
What I've done to do this is insert a pdb.set_trace() right before the
place your test fails, then in pdb do Ctrl+C to break out of the test.
This leaves your test database intact at that state. Then you can
change your settings to point to the test database instead of your
regular one. Then you can runserver or dumpdata etc..

Good luck!
- Steve Bywater

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save out a test database?

2011-06-02 Thread Margie Roginski
Karen Tracy, if you are reading this, could you comment?

As the person that seems to be most knowledgable about django testing
(your Django 1.1 Testing book is fantastic - I highly recommend it!),
can you confirm that something like this is the best way to go?  It
seems strange to me that there is no more standard way of dumping the
database from inside a test so that the state can be replicated for
use in a runserver environment.

Margie

On Jun 1, 2:01 pm, Kirill Spitsin  wrote:
> On Wed, Jun 01, 2011 at 11:59:28AM -0700, Margie Roginski wrote:
> > That's a good pointer, thanks.  However I'm still confused about how I
> > can actually dump out the data from my test run?  For example, say I
> > have a particular test and I want to dump the data at some certain
> > point.  I can put in pdb.set_trace() in the code to stop at the
> > appropriate point, but what do I call from that point to create the
> > mydata.json file that then gets loaded with the command
>
> >   django-admin.py testserver mydata.json
> >>> from django.core.serializers import serialize
> >>> queryset1 = Model1.objects.filter(...)
> >>> queryset2 = Model2.objects.filter(...)
> >>> fixture = serialize('json', list(queryset1) + list(queryset2))
> >>> f = open('mydate.json', 'w')
> >>> f.write(fixture)
> >>> f.close()
>
> --
> Kirill Spitsin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save out a test database?

2011-06-01 Thread Kirill Spitsin
On Wed, Jun 01, 2011 at 11:59:28AM -0700, Margie Roginski wrote:
> That's a good pointer, thanks.  However I'm still confused about how I
> can actually dump out the data from my test run?  For example, say I
> have a particular test and I want to dump the data at some certain
> point.  I can put in pdb.set_trace() in the code to stop at the
> appropriate point, but what do I call from that point to create the
> mydata.json file that then gets loaded with the command
> 
>   django-admin.py testserver mydata.json

>>> from django.core.serializers import serialize
>>> queryset1 = Model1.objects.filter(...)
>>> queryset2 = Model2.objects.filter(...)
>>> fixture = serialize('json', list(queryset1) + list(queryset2))
>>> f = open('mydate.json', 'w')
>>> f.write(fixture)
>>> f.close()

-- 
Kirill Spitsin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save out a test database?

2011-06-01 Thread Margie Roginski
That's a good pointer, thanks.  However I'm still confused about how I
can actually dump out the data from my test run?  For example, say I
have a particular test and I want to dump the data at some certain
point.  I can put in pdb.set_trace() in the code to stop at the
appropriate point, but what do I call from that point to create the
mydata.json file that then gets loaded with the command

  django-admin.py testserver mydata.json

Thanks!

Margie


On May 29, 7:28 pm, Jason Culverhouse  wrote:
> On May 29, 2011, at 7:13 PM, Margie Roginski  wrote:
>
> > Anyone know if there is a way to save out a test database that is
> > created through the django TestCase module?
>
> I think this gets you close:
>
> https://docs.djangoproject.com/en/1.2/ref/django-admin/#testserver-fi...
>
> django-admin.py testserver
> Runs a Django development server (as in runserver) using data from the given 
> fixture(s).
>
>
>
>
>
>
>
> > IE, say I have a test that runs part way through.   I'd like to save
> > it out and then modify my settings.py to refer to the saved out test
> > database and take a look at it via my web client (ie, runserver) - is
> > that possible?
>
> > Thanks for any pointers,
>
> > Margie
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save out a test database?

2011-05-29 Thread Jason Culverhouse

On May 29, 2011, at 7:13 PM, Margie Roginski  wrote:

> Anyone know if there is a way to save out a test database that is
> created through the django TestCase module?
> 

I think this gets you close:

https://docs.djangoproject.com/en/1.2/ref/django-admin/#testserver-fixture-fixture

django-admin.py testserver
Runs a Django development server (as in runserver) using data from the given 
fixture(s).



> IE, say I have a test that runs part way through.   I'd like to save
> it out and then modify my settings.py to refer to the saved out test
> database and take a look at it via my web client (ie, runserver) - is
> that possible?
> 
> Thanks for any pointers,
> 
> Margie
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Jeff Blaine
Thank you both.  That's a great explanation, Jacob.  I'll consider your 
message more closely and play around on Monday a bit.

PS: I said it *seems* broken to me, as in "Maybe I just don't understand the 
reason.", which I clearly didn't :)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Jacob Kaplan-Moss
On Fri, Apr 29, 2011 at 12:17 PM, Jeff Blaine  wrote:
> "primary_key=True implies null=False and unique=True. Only one primary key
> is allowed on an object."
> So that unique=True part is inaccurate?  Or is that, again, another thing
> that will fail only at validation?

Maybe this'll help::

# Log every SQL query
>>> import logging
>>> l = logging.getLogger('django.db.backends')
>>> l.setLevel(logging.DEBUG)
>>> l.addHandler(logging.StreamHandler())

# Now let's play...
>>> from myapp.models import Device
>>> d1 = Device()
>>> d1.save()
(0.002) SELECT (1) AS "a" FROM "cfpk_device" WHERE
"cfpk_device"."propertyno" = E''  LIMIT 1; args=('',)
(0.001) INSERT INTO "cfpk_device" ("propertyno") VALUES (E''); args=('',)

>>> d2 = Device()
>>> d2.save()
(0.001) SELECT (1) AS "a" FROM "cfpk_device" WHERE
"cfpk_device"."propertyno" = E''  LIMIT 1; args=('',)

You have to remember that `object.save()` could mean INSERT *or*
UPDATE depending on whether the object with the given primary key
exists or not. When you create a new device, because again the default
is the empty string, you've already got one of those in the DB. Django
notices that it doesn't need updating, and so it doesn't update it.

Now consider this:

>>> d2.save()
(0.001) INSERT INTO "cfpk_device" ("propertyno") VALUES (E''); args=('',)
Traceback (most recent call last):
...
IntegrityError: duplicate key value violates unique constraint
"cfpk_device_pkey"
DETAIL:  Key (propertyno)=() already exists.

If you force an insert, you'll see the error you're expecting.

I'm sorry if you think it's broken. I disagree, though: Django's
working the way we designed it to work. You've exposed a subtle
edge-case (which shows just one reason why I use surrogate keys almost
without exception).

Jacob

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Javier Guerra Giraldez
On Fri, Apr 29, 2011 at 12:17 PM, Jeff Blaine  wrote:
> "primary_key=True implies null=False and unique=True. Only one primary key
> is allowed on an object."
> So that unique=True part is inaccurate?  Or is that, again, another thing
> that will fail only at validation?

did you test pass more than once?

check the saved object(s?), is the primary key field a zero string, or
NULL?  most databases consider NULL non-equal to any value, including
other NULLs, and allow multiple records with NULLs in a unique field.

also, some databases consider the zero string a valid representation
for NULL.  which RDBMS are you using?

-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Jeff Blaine
"primary_key=True implies 
null=False
 and 
unique=True.
 
Only one primary key is allowed on an object."

So that unique=True part is inaccurate?  Or is that, again, another thing 
that will fail only at validation?

This seems pretty broken to me :(

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Jacob Kaplan-Moss
On Fri, Apr 29, 2011 at 11:47 AM, Jeff Blaine  wrote:
> How is this possible based on the model below?
> d = Device()
> d.save()
> # no errors
> class Device(models.Model):
>     propertyno      = models.CharField('Property Number',
>                                        max_length=10,
>                                        primary_key=True)

It's because CharField have a `default` of "" -- that is, the empty
string. So you've created a Device with a propertyno of "" (again, an
empty string). That's a valid pk value as far as some DBs are
concerned.

Notice that the model won't validate -- because you haven't set
`blank` to `True` -- but it will save. (For backwards-compatibility
reasons, save() can't trigger validation).

Jacob

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Jeff Blaine
A specified primary_key should not be auto-incrementing from my 
understanding.  The following shows 2 objects with the same value for a 
field I specified should be the primary_key:

>>> from hostdb.models import Device
>>> d = Device()
>>> d.propertyno
''
>>> d.save()
>>> d = Device()
>>> d.propertyno
''
>>> d.save()
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Jeff Blaine
"If Django sees you've explicitly set 
Field.primary_key,
 
it won't add the automatic id column."

http://docs.djangoproject.com/en/1.3/topics/db/models/#automatic-primary-key-fields

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Cal Leeming [Simplicity Media Ltd]
I think because the primary_key field auto defaults to be auto-inc?

On Fri, Apr 29, 2011 at 5:47 PM, Jeff Blaine  wrote:

> How is this possible based on the model below?
>
> d = Device()
> d.save()
> # no errors
>
> class Device(models.Model):
>
> propertyno  = models.CharField('Property Number',
>max_length=10,
>primary_key=True)
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save uploaded file to remote machines?

2010-12-28 Thread Daniel Hilton
On 28 December 2010 07:12, Andy  wrote:
> I'm using forms.FileField() to allow users to upload photos.
>
> After a photos is uploaded, I want to save the photo to one or more
> than one remote machine(s) which are dedicated to serving images. How
> do I do that?
>
> Thanks.

Have a look at this app:
https://github.com/seanbrant/django-queued-storage

That will manage moving the file to a backend storage system (s3, SAN,
etc) and handle the movement time as well.

HTH
Dan

>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>



-- 
Dan Hilton

www.twitter.com/danhilton
www.DanHilton.co.uk


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save Handlers and a newbie to Django

2010-10-15 Thread Devin M
Thanks everyone, I tried using some signal handlers but it wasn't
happening so I reverted to the override of the save method and now I
have it working.

Regards,
Devin Morin

On Oct 15, 8:56 am, Blue Cuenca  wrote:
>  On 10/15/2010 9:01 PM, Devin M wrote:> Hello everyone,
> >     I am writing a save handler in my models.py file to run a few
> > actions after a save. to do this I have a function called make_photos
> > and a connection to the post_save signal.
> > Here is my code:
>
> > 
> > The only problem i have with this code is that it runs every save. So
> > it creates a infinite loop of sorts and I dont know how to make it
> > perform this action once. Is there another signal I should use? Any
> > ideas?
>
> > Regards,
> > Devin M
>
> You may want to look at 
> this:http://snipt.net/danfreak/generate-thumbnails-in-django-with-pil/
>
> The snippet above overrides the save method.  Before calling the actual
> save (super), the thumbnail fields is dynamically created (using PIL).
> I am sure you can add code that will do the same thing for your "large"
> photo field.
>
> regards,
> Blue C

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save Handlers and a newbie to Django

2010-10-15 Thread Blue Cuenca
 On 10/15/2010 9:01 PM, Devin M wrote:
> Hello everyone,
> I am writing a save handler in my models.py file to run a few
> actions after a save. to do this I have a function called make_photos
> and a connection to the post_save signal.
> Here is my code:
>
> 
> The only problem i have with this code is that it runs every save. So
> it creates a infinite loop of sorts and I dont know how to make it
> perform this action once. Is there another signal I should use? Any
> ideas?
>
> Regards,
> Devin M
>
You may want to look at this:
http://snipt.net/danfreak/generate-thumbnails-in-django-with-pil/

The snippet above overrides the save method.  Before calling the actual
save (super), the thumbnail fields is dynamically created (using PIL). 
I am sure you can add code that will do the same thing for your "large"
photo field.


regards,
Blue C

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save Handlers and a newbie to Django

2010-10-15 Thread Devin M
Im just storing these files in standard ImageFields does the field
take care of that automagically?
And whats the best way to delete the files saved to tmp? should i do a
system call for rm?


On Oct 15, 7:41?am, Jonathan Barratt 
wrote:
> On 15 ?.?. 2010, at 21:35, Devin M wrote:
>
> > Ok its running in a infinite loop because im calling
> > self.*photo.save() and that starts this loop all over again. Maybe I
> > can add a field to the model like booleen resized and if its true dont
> > do any resizing but if its false then perform some resizing(aka run
> > the function)? also im going to have to delete these files when the
> > object is deleted too.
>
> You can also override the delete function to take care of deleting the files 
> when you're getting rid of the object...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save Handlers and a newbie to Django

2010-10-15 Thread Jonathan Barratt

On 15 ?.?. 2010, at 21:35, Devin M wrote:

> Ok its running in a infinite loop because im calling
> self.*photo.save() and that starts this loop all over again. Maybe I
> can add a field to the model like booleen resized and if its true dont
> do any resizing but if its false then perform some resizing(aka run
> the function)? also im going to have to delete these files when the
> object is deleted too.

You can also override the delete function to take care of deleting the files 
when you're getting rid of the object...


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save Handlers and a newbie to Django

2010-10-15 Thread Jonathan Barratt
On 15 ?.?. 2010, at 20:01, Devin M wrote:

> Hello everyone,
>I am writing a save handler in my models.py file to run a few
> actions after a save. to do this I have a function called make_photos
> and a connection to the post_save signal.
> Here is my code:

> 
> The only problem i have with this code is that it runs every save. So
> it creates a infinite loop of sorts and I dont know how to make it
> perform this action once. Is there another signal I should use? Any
> ideas?

Admittedly I didn't check this idea against your code, but it just sprung to 
mind since the problem is the infinite loop: could you just define your own 
save method and do the necessary post-save work from there? My thought is that 
this would get out of the post_save signal-loop problem. See: 
http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods

Not sure that it'll let you do what you need, but you'll be able to tell 
whether that's the case or not quicker than I! :)

Good luck!
Jonathan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save Handlers and a newbie to Django

2010-10-15 Thread Devin M
Ok its running in a infinite loop because im calling
self.*photo.save() and that starts this loop all over again. Maybe I
can add a field to the model like booleen resized and if its true dont
do any resizing but if its false then perform some resizing(aka run
the function)? also im going to have to delete these files when the
object is deleted too.

On Oct 15, 6:01 am, Devin M  wrote:
> Hello everyone,
>     I am writing a save handler in my models.py file to run a few
> actions after a save. to do this I have a function called make_photos
> and a connection to the post_save signal.
> Here is my code:
> class Album(models.Model):
>     title = models.CharField(max_length=200)
>     date = models.DateField(blank=True, null=True)
>     desc = models.TextField(blank=True, null=True)
>     comments = models.BooleanField()
>     published = models.BooleanField(default=True)
>     tags = models.CharField(max_length=200, blank=True, null=True)
>     def __unicode__(self):
>         return u'%s' % (self.title)
>
> class Photo(models.Model):
>     title = models.CharField(max_length=200, default='Untitled Photo')
>     album = models.ForeignKey(Album, blank=True, null=True)
>     desc = models.TextField(blank=True, null=True)
>     date = models.DateField(blank=True, null=True)
>     comments = models.BooleanField()
>     published = models.BooleanField(default=True)
>     tags = models.CharField(max_length=200, blank=True, null=True)
>     thumb_photo = models.ImageField(upload_to='thumb_images',
> blank=True, null=True)
>     large_photo = models.ImageField(upload_to='large_images',
> blank=True, null=True)
>     original_photo = models.ImageField(upload_to='original_images',
> blank=True, null=True)
>     def makeimages(self):
>         (dirName, fileName) = os.path.split(self.original_photo.path)
>         (fileBaseName, fileExtension)=os.path.splitext(fileName)
>
>         #Save the thumbnail
>         thumb_width = 300
>         thumb_height = 300
>         thumb = Image.open(self.original_photo.path)
>         thumb.resize((thumb_width,thumb_height), Image.ANTIALIAS)
>         thumb_path = "/tmp/" + str(fileBaseName) + "_thumb.jpg"
>         thumb.save(thumb_path, "JPEG")
>         thumb_img_file = open(thumb_path, 'r')
>         thumb_file = File(thumb_img_file)
>         self.thumb_photo.save(str(fileBaseName) + '_thumb.jpg',
> thumb_file, save=True)
>         thumb_img_file.close()
>
>         #Save the large
>         large_width = 1024
>         large_height = 768
>         large = Image.open(self.original_photo.path)
>         large.resize((large_width,large_height), Image.ANTIALIAS)
>         large_path = "/tmp/" + str(fileBaseName) + "_large.jpg"
>         large.save(thumb_path, "JPEG")
>         large_img_file = open(thumb_path, 'r')
>         large_file = File(thumb_img_file)
>         self.thumb_photo.save(str(fileBaseName) + '_large.jpg',
> large_file, save=True)
>         large_img_file.close()
>
>         post_save.connect(makeimages)
>
> The only problem i have with this code is that it runs every save. So
> it creates a infinite loop of sorts and I dont know how to make it
> perform this action once. Is there another signal I should use? Any
> ideas?
>
> Regards,
> Devin M

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save() isn't thread-safe?

2010-08-27 Thread Karen Tracey
On Fri, Aug 27, 2010 at 5:07 AM, Andy  wrote:

> In this presentation save() is described as not thread-safe and
> update() is recommended to be used instead of save():
>
> http://www.slideshare.net/zeeg/db-tips-tricks-django-meetup  (page
> 2, 3, 4)
>
> Is it true that save() is not thread-safe? How is it not? Should I
> avoid using save() and use update() instead?
>

It's a matter of what your code is doing. While you can write code using
save() in a way that is not thread-safe, you do not necessarily need to
switch to update() to fix the issue. Consider code like this in a view:

for answer in chosen_answers:
answer.votes += 1
answer.save()

That is not thread-safe. Running on a production web server, that block of
code may be simultaneously running to handle multiple different requests.
Incrementing the vote count in the view, based on whatever was read earlier
and may now be stale, runs the risk of losing votes. A thread-safe version
is:

from django.db.models import F
for answer in chosen_answers:
answer.votes = F('votes') + 1
answer.save()

The use of an F() expression (
http://docs.djangoproject.com/en/dev/ref/models/instances/#updating-attributes-based-on-existing-fields)
will push the responsibility for ensuring the value is atomically updated
onto the database.

(Example code taken from the book you can find by following the link in my
sig...there are more details of how to test for such issues in the book.)

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save inline models when saving the father in admin

2010-08-26 Thread Karen Tracey
On Thu, Aug 26, 2010 at 12:02 PM, Alessandro Ronchi <
alessandro.ron...@soasi.com> wrote:

> I need to be sure that an inline model is saved every time I save its
> parent class.
> I need it because I want to save the last modified timestamp, and I don't
> want to overwrite the parent save because I want to track only admin saves.
>
> I cannot touch the parent class because it came from a library.
>
> Is it possible?
>

Yes. Override save_formset for the ModelAdmin containing the inline:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_formset

Note the formset.save() only returns the modified objects -- the ones that
based on data changing appear to need to be saved. You'll also need to save
any of the initial forms (formset.initial_forms) that don't appear to be
modified, if you want to save all of the objects even if the form data has
not changed from initial values.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save a values_list to a charfield

2010-07-27 Thread Nick
It is a bit of a last minute deal and will be changed after today, but
we had a handful of "improvements" handed down to us from management
and this was the fastest thing we could come up with using some old
mysql query logic and several already built templates for output.

I appreciate the help.

On Jul 27, 2:49 pm, ringemup  wrote:
> ', '.join(primary_ids)
>
> The fact that you're doing this with foreign keys, though, suggests to
> me that you may have a database normalization problem.
>
> On Jul 27, 3:26 pm, Nick  wrote:
>
> > I am getting this to save but I can't get it to output properly
>
> > it's outputting as [16L, 451L, 521L] for a list of id's, which it
> > should according to documentation.  However, how can I output it like
> > this 16, 451, 521
>
> > On Jul 27, 12:11 pm, Nick  wrote:
>
> > > I am needing to do some duct taping for a project that is going on
> > > right now. In it I need to take a values_list of id's from a
> > > ManyToMany field and save those values to a varchar field so a mysql
> > > query can access the values. I am working with two different sets of
> > > developers and this is the best we can come up with in such a short
> > > period of time
>
> > > Here is the model:
>
> > > Candidate
> > >     filing_id = models.IntegerField()
> > >     name = models.CharField()
>
> > > Race:
> > >     name = models.CharField()
> > >     primary_advance = models.ManyToManyField('Candidate')
> > >     primary_advnace_list = models.CahrField()
>
> > >     def(save, *args, **kwargs):
> > >         primary_ids = self.primary_advace.values_list('id', flat=True)
> > >         if primary_ids.count() > 0:
> > >             primary_advance_list = primary_ids
> > >         else:
> > >             primary_advance_list = []
> > >         super(Race, self).save(*args, **kwargs)
>
> > > I've tried this but I'm coming back with empty values for the list
> > > fields.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save a values_list to a charfield

2010-07-27 Thread ringemup

', '.join(primary_ids)

The fact that you're doing this with foreign keys, though, suggests to
me that you may have a database normalization problem.

On Jul 27, 3:26 pm, Nick  wrote:
> I am getting this to save but I can't get it to output properly
>
> it's outputting as [16L, 451L, 521L] for a list of id's, which it
> should according to documentation.  However, how can I output it like
> this 16, 451, 521
>
> On Jul 27, 12:11 pm, Nick  wrote:
>
> > I am needing to do some duct taping for a project that is going on
> > right now. In it I need to take a values_list of id's from a
> > ManyToMany field and save those values to a varchar field so a mysql
> > query can access the values. I am working with two different sets of
> > developers and this is the best we can come up with in such a short
> > period of time
>
> > Here is the model:
>
> > Candidate
> >     filing_id = models.IntegerField()
> >     name = models.CharField()
>
> > Race:
> >     name = models.CharField()
> >     primary_advance = models.ManyToManyField('Candidate')
> >     primary_advnace_list = models.CahrField()
>
> >     def(save, *args, **kwargs):
> >         primary_ids = self.primary_advace.values_list('id', flat=True)
> >         if primary_ids.count() > 0:
> >             primary_advance_list = primary_ids
> >         else:
> >             primary_advance_list = []
> >         super(Race, self).save(*args, **kwargs)
>
> > I've tried this but I'm coming back with empty values for the list
> > fields.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save a values_list to a charfield

2010-07-27 Thread Nick
I am getting this to save but I can't get it to output properly

it's outputting as [16L, 451L, 521L] for a list of id's, which it
should according to documentation.  However, how can I output it like
this 16, 451, 521

On Jul 27, 12:11 pm, Nick  wrote:
> I am needing to do some duct taping for a project that is going on
> right now. In it I need to take a values_list of id's from a
> ManyToMany field and save those values to a varchar field so a mysql
> query can access the values. I am working with two different sets of
> developers and this is the best we can come up with in such a short
> period of time
>
> Here is the model:
>
> Candidate
>     filing_id = models.IntegerField()
>     name = models.CharField()
>
> Race:
>     name = models.CharField()
>     primary_advance = models.ManyToManyField('Candidate')
>     primary_advnace_list = models.CahrField()
>
>     def(save, *args, **kwargs):
>         primary_ids = self.primary_advace.values_list('id', flat=True)
>         if primary_ids.count() > 0:
>             primary_advance_list = primary_ids
>         else:
>             primary_advance_list = []
>         super(Race, self).save(*args, **kwargs)
>
> I've tried this but I'm coming back with empty values for the list
> fields.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save as inline formset

2010-02-10 Thread Karen Tracey
On Wed, Feb 10, 2010 at 7:45 AM, oiad  wrote:

> Hi. If I have a couple of models like these:
>
> class Poll(models.Model):
>question = models.CharField(max_length=200, unique = True)
>pub_date = models.DateTimeField('date published')
>
> class Choice(models.Model):
>poll = models.ForeignKey(Poll)
>choice = models.CharField(max_length=200)
>votes = models.IntegerField()
>
> and in admin.py I put "save_as=True" and I try to save a poll as a new
> one, but I forget to change the question, since I want that to be
> unique, I get an error as it supposed to be, but if I change the
> question and try to save the poll I get this error:
> invalid literal for int() with base 10: ''


This looks like a bug somewhere along the line of processing that sequence
(save-as that fails due to a validation error for an object with at least
one inline, correct the error, try to save again), though I'm not sure
where.  I don't recall this being reported before so if you could open a
ticket for it that would be good.

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: save() got an unexpected keyword argument 'using'

2010-02-02 Thread Russell Keith-Magee
On Wed, Feb 3, 2010 at 2:12 PM, Ramdas S  wrote:
> I just upgraded to the latest trunk SVn 12377, and this error has started
> propping up on some of my existing working code.
>
> Here is the traceback
>
> http://dpaste.com/153987/
>
>
> Apparently get_or_create is not working properly at least as per docs and
> its expecting a using keyword. Any idea how to fix this?

get_or_create() is working fine - the problem is with your save
method. save() can receive a number of keyword arguments, and that
list of keyword arguments is occasionally subject to change. Django
1.2 adds a 'using' to the list of possible arguments, but your custom
save method doesn't accept 'using' as an argument.

This is why the docs recommend [1] defining custom save methods as:

def save(self, *args, **kwargs):
# custom pre-save
super(MyModel, self).save(*args, **kwargs)
# custom post-save

This ensures that your save() methods accept any arguments that might
be added in the future.

[1] 
http://docs.djangoproject.com/en/1.1/topics/db/models/#overriding-model-methods

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save inline instances first

2010-01-18 Thread Marco Rogers

I had a need for this at one point because my main model had an
overridden save method that would modify the inlines. But it didn't
work because the inlines weren't there. I had to reverse the save
method and put it on the inline model. But in my case, there was no
reason not to do that.

:Marco


On Jan 18, 8:14 am, Karen Tracey  wrote:
> On Mon, Jan 18, 2010 at 6:23 AM, Gabriel Reis  wrote:
> > In the ModelAdmin using inline forms I would like to know if it is possible
> > to save the inline instances first/before saving the instance edited by the
> > main ModelAdmin form.
>
> Why do you want to?
>
> It can't be done when you are adding a new main model, since the inlines
> have a ForeignKey to the main model and the main model needs to have a
> primary key (thus needs to have been saved) before the inlines can be
> saved.  (For changes it might could be made to work, but it is not the way
> the admin code is written: it first saves the main model, then the inlines,
> just as it does for adding.)
>
> Karen
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Save, Signals and Models

2010-01-18 Thread Victor Loureiro Lima
Thanks Eric, that worked like a charm. I've never got to use the update,
thus I had no idea of its existence, fair enough that is exactelly what I
needed.

Thank you very much, and other who have answered this thread.
Victor Lima

2010/1/16 Eric Chamberlain 

>
> On Jan 15, 2010, at 4:22 PM, Victor Loureiro Lima wrote:
>
> > Here is the deal:
> >
> > class MyModel ( models.Model ):
> >   title = models.CharField( max_length = 100 )
> >   only_me = models.BooleanField( default = False )
> >
> >  Question: Whats the proper way to guarantee that no matter how many
> MyModel's are available in the database, only one of them
> > will have the only_me set as True? To further clarify things: In the
> admin, whenever I check the only_me checkbox, and save my model, all other
> models of this class will have to have its own only_me field set to false.
> >
> >  As far as I know, there is no other way of doing this unless I iterate
> over all MyModel' s objects and uncheck them if they are checked, save them,
> then afterwards check the model that I am actually saving setting the
> only_me field to True.
> >
> >  I tried doing this on the actual save() of the model, no success.
> Everytime I called save on iterated objects, I, of course, got the maximum
> recursive depth error thrown at me.
> >  Fair enough, I quickly thought about signals, hooking my function to
> post_save(), however I inevitabilly stumbled upon the same
> > problem: When I called save() on the iterated objects the post_save
> signal got sent, I would step again in the same function, thus
> > no cookie for me.
> >  I jumped over to overriding AdminForm' s save() method, so that I would
> iterate there on the models unchecking them if necessary, and them returning
> the proper object, but I stopped that and I said to myself that I must be
> doing something really stupid, so Im coming to you guys: What would the
> propper way of doing this?
> >
>
> def save(self, force_insert=False, force_update=False):
>if self.only_me is True:
># if this is the new default, set others to False
>MyModel.objects.exclude(pk=self.pk).update(only_me=False)
>
>super(MyModel, self).save(force_insert, force_update) # Call the
> "real" save() method.
>
>
> --
> Eric Chamberlain, Founder
> RF.com - http://RF.com/
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Save inline instances first

2010-01-18 Thread Karen Tracey
On Mon, Jan 18, 2010 at 6:23 AM, Gabriel Reis  wrote:

> In the ModelAdmin using inline forms I would like to know if it is possible
> to save the inline instances first/before saving the instance edited by the
> main ModelAdmin form.
>

Why do you want to?

It can't be done when you are adding a new main model, since the inlines
have a ForeignKey to the main model and the main model needs to have a
primary key (thus needs to have been saved) before the inlines can be
saved.  (For changes it might could be made to work, but it is not the way
the admin code is written: it first saves the main model, then the inlines,
just as it does for adding.)

Karen
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Save, Signals and Models

2010-01-16 Thread Eric Chamberlain

On Jan 15, 2010, at 4:22 PM, Victor Loureiro Lima wrote:

> Here is the deal:
> 
> class MyModel ( models.Model ):
>   title = models.CharField( max_length = 100 )
>   only_me = models.BooleanField( default = False )
> 
>  Question: Whats the proper way to guarantee that no matter how many 
> MyModel's are available in the database, only one of them
> will have the only_me set as True? To further clarify things: In the admin, 
> whenever I check the only_me checkbox, and save my model, all other models of 
> this class will have to have its own only_me field set to false.
> 
>  As far as I know, there is no other way of doing this unless I iterate over 
> all MyModel' s objects and uncheck them if they are checked, save them, then 
> afterwards check the model that I am actually saving setting the only_me 
> field to True.
> 
>  I tried doing this on the actual save() of the model, no success. Everytime 
> I called save on iterated objects, I, of course, got the maximum recursive 
> depth error thrown at me. 
>  Fair enough, I quickly thought about signals, hooking my function to 
> post_save(), however I inevitabilly stumbled upon the same
> problem: When I called save() on the iterated objects the post_save signal 
> got sent, I would step again in the same function, thus
> no cookie for me.
>  I jumped over to overriding AdminForm' s save() method, so that I would 
> iterate there on the models unchecking them if necessary, and them returning 
> the proper object, but I stopped that and I said to myself that I must be 
> doing something really stupid, so Im coming to you guys: What would the 
> propper way of doing this?
> 

def save(self, force_insert=False, force_update=False):
if self.only_me is True:
# if this is the new default, set others to False
MyModel.objects.exclude(pk=self.pk).update(only_me=False)

super(MyModel, self).save(force_insert, force_update) # Call the "real" 
save() method.


--
Eric Chamberlain, Founder
RF.com - http://RF.com/







-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Save, Signals and Models

2010-01-15 Thread Mike Ramirez
On Friday 15 January 2010 17:11:23 Victor Loureiro Lima wrote:
> I did exactelly that, instead of using id I used the slug, which is also
> unique, so I skipped it,
> but the problem still occurs. Either my logic is wrong, or some dumb
> mistake, but I think that wouldnt work either.
> 
> Victor Lima
> 

I just rechecked the django docs, the reason post_save() doesn't work is cause 
post save is at the _end_ of the save method, end isn't after the save is 
executed, but after all the instructions are executed in the save method. Yes 
everytime you call save(), even in the loop that bit of code is getting called 
all the time.

You should update this in the model admin after the save is complete, send a 
custom single or call a manager method (mangers are meant ot work at the table 
level, as opposed to models working on the row level) or put this code bit in 
a function you call in the model admin after saving.  Ideally I would put it 
in a custom singal and send that after the save, where ever I needed it.


Mike
-- 
Do people know you have freckles everywhere?


signature.asc
Description: This is a digitally signed message part.


Re: Save, Signals and Models

2010-01-15 Thread Mike Ramirez
On Friday 15 January 2010 17:08:06 Mike Ramirez wrote:
>  Add in an if statement, one that while cycling through the only_me=True
>  list, ignores the current model you're saving.
> 
>  def save(self):
>  if self.only_me:
>  only_me_true = MyModel.objects.filter(only_me=True)
>  for obj in only_me_true:
>   if obj.id != self.id:
>   obj.only_me = False
>obj.save()
> MyModel.save(self)
> 

Sorry for the bad formatting -- hope this helps.

  def save(self, *args, **kwargs):
if self.only_me:
  only_me_true = MyModel.objects.filter(only_me=True)
  for obj in only_me_true:
  if obj.id != self.id:
obj.only_me = False
obj.save()
super(MyModel, self).save(*args, **kwargs)


Mike
-- 
What upsets me is not that you lied to me, but that from now on I can no
longer believe you.
-- Nietzsche


signature.asc
Description: This is a digitally signed message part.


  1   2   >