Re: Django in Linux set image

2018-12-10 Thread PASCUAL Eric
Hi,


Which server are you using ? Is is runserver ?


When running in debug mode, it serves statics, but not when debug mode is 
turned off.

If you Google with "django runserver static debug" you'll get this hit in the 
very first ones :
https://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail


The thread explains all the details and gives pointers to the reference 
documentation.


BTW, never use runserver in production. It is not done for that at all, for 
performances and security reasons.


Additionally, as explained in Django doc, statics should not be served by the 
Django app, but by the reverse proxy such as Nginx, which sits in front of the 
Django app and routes requests to the WSGI server, while serving directly 
static assets such as img, js, css...


An other option for statics if you don't want to dive too much into your 
reverse proxy settings for configuring the static routing is to use Django 
middlewares such as whitenoise (http://whitenoise.evans.io/en/stable/), which 
does a quite good job for static serving optimization. This should suffice for 
sites not too much demanding in terms of traffic.


Best regards


Eric


From: django-users@googlegroups.com  on behalf 
of pujiarahman 
Sent: Monday, December 10, 2018 3:28:19 AM
To: Django users
Subject: Django in Linux set image

Hi all,

i have instaled django in ubuntu,
i have image and i put in folder (img), the locate is

blog
urls.py
views.py
admin.py
--static
-- blog
-dist
---img

When i load my browser The image is fine no problem, the problem is when,
i config the settings.py  to :

DEBUG = False
ALLOWED_HOSTS = ['localhost', '27.0.0.1', 'xxx.xxx.xxx.xxx', '[::1]']

the image can not found, but when i set Debug to True , the image come back 
normal.
is there any miss in my config settings.py

this my home.html

{% load static %}









NOC
Member since Nov. 2018


..


Regards

Sidik


--
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/7b30d6a2-c1e0-45fb-8722-3b38ed6fd062%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/VI1P193MB0432DDD00D4084DC21234D968CA50%40VI1P193MB0432.EURP193.PROD.OUTLOOK.COM.
For more options, visit https://groups.google.com/d/optout.


Re: Django UpdateView and Createview

2018-12-10 Thread Rupam Hazra
Hi all,

I know and understand how update view working but in my case how to 
implement on my case.

Please suggest.;

On Sunday, 9 December 2018 23:13:04 UTC+5:30, Okware Aldo wrote:
>
> Ryan's suggestion should give you a starting point. 
>
> On Sun, Dec 9, 2018 at 3:43 PM Deepak Kumar  > wrote:
>
>> On Sunday, December 9, 2018 at 6:21:55 AM UTC+5:30, Ryan Nowakowski wrote:
>> > Take a look at 
>> https://docs.djangoproject.com/en/2.1/topics/class-based-views/generic-editing/
>> > 
>> > 
>> > On December 7, 2018 7:09:25 AM CST, Rupam Hazra  
>> wrote:
>> > 
>> > Hi,
>> > 
>> > 
>> > I have working in a TaskManagement Sytem where i have project module 
>> and technology module.
>> > 
>> > 
>> > class ProjectMaster(models.Model):
>> > name=models.CharField(max_length=255,blank=True,null=True)
>> > description=models.CharField(max_length=255,blank=True,null=True)
>> > is_agreement_sent=models.BooleanField(default=False)
>> > is_invoice_create=models.BooleanField(default=False)
>> > is_invoice_sent=models.BooleanField(default=False)
>> > is_paid=models.BooleanField(default=False)
>> > status=models.BooleanField(default=True)
>> > is_deleted=models.BooleanField(default=False)
>> > created_at=models.DateTimeField(auto_now_add=True)
>> > created_by = models.ForeignKey(User, 
>> on_delete=models.CASCADE,related_name='createdUser',blank=True,null=True)
>> > updated_at=models.DateTimeField(auto_now_add=True)
>> > updated_by=models.ForeignKey(User, on_delete=models.CASCADE, 
>> related_name='UpdUser',blank=True,null=True)
>> > #technology_master = models.ForeignKey(TechnologyMaster, 
>> on_delete=models.CASCADE, related_name='technologies', )
>> > 
>> > def __str__(self):
>> > return str(self.name)
>> > class TechnologyMaster(models.Model):
>> > #projectmaster = 
>> models.ForeignKey(ProjectMaster,on_delete=models.CASCADE)
>> > name=models.CharField(max_length=255,blank=True,null=True)
>> > status = models.BooleanField(default=True)
>> > is_deleted = models.BooleanField(default=False)
>> > created_at = models.DateTimeField(auto_now_add=True)
>> > created_by = models.ForeignKey(User, 
>> on_delete=models.CASCADE,blank=True, null=True,related_name='created_by')
>> > updated_at = models.DateTimeField(auto_now_add=True)
>> > updated_by = models.ForeignKey(User, 
>> on_delete=models.CASCADE,blank=True, null=True,related_name='updated_by')
>> > def __str__(self):
>> > return str(self.id)+'-'+ self.nameHere one functionality is 
>> one project has multiple technologies so i have made one mapping table 
>> belowclass ProjectTechnologyMapping(models.Model):
>> > project_master = models.ForeignKey(ProjectMaster, 
>> on_delete=models.CASCADE, related_name='projects')
>> > technology_master = models.ForeignKey(TechnologyMaster, 
>> on_delete=models.CASCADE, related_name='technologies')
>> > status = models.BooleanField(default=True)
>> > is_deleted = models.BooleanField(default=False)
>> > created_at = models.DateTimeField(auto_now_add=True)
>> > created_by = models.ForeignKey(User, 
>> on_delete=models.CASCADE,blank=True,null=True,related_name='pro_tech_created_user')
>> > updated_at = models.DateTimeField(auto_now_add=True)
>> > updated_by = models.ForeignKey(User, 
>> on_delete=models.CASCADE,blank=True,null=True,related_name='pro_tech_updated_user')
>> > def __str__(self):
>> > return str(self.id)So, my question is how add and update using 
>> django createview,updateview (generic view) using templates.
>>
>> -- 
>> 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/b0be82da-dca5-4594-9f22-e0c3323adc3b%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/fc5e6fe9-3169-4c7e-8aec-dc1880718cda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Subclassing Django Views Issue

2018-12-10 Thread Shazia Nusrat
Can someone help me with subclassing django-views as I couldn't understand
the pattern to work with.
Following is the link to see the code.

https://github.com/AndrewIngram/django-extra-views/issues/187

Regards,

Shazia

-- 
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/CAD83tOwouuGW2fTO2Wvn_nobfcBuZO41u-H3jDGxBfT6OGDL3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Oracle Production DBA automation -django based dbawebmenu application

2018-12-10 Thread Ketan
Dear All,


Recently, I have developed new django based application which is useful for 
Oracle Database Administrator for their daily operational task. Programming 
is not my major skill. Most of my experience in Oracle Production Support 
only but automation is my strong desire and due to that,  almost after 15 
years I learned myself python and django recently and finally developed 
first application which probably useful for Oracle RAC/Non-RAC DBA.  

URL : https://automationdba.herokuapp.com

Source Code : https://github.com/automationdba/automationdba.git

I will be pleased if this application can be useful for some one for their 
day to day activity.

Regards,
Ketan

-- 
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/dfbb3654-2ddc-422f-938b-e0a428124f1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django in Linux set image

2018-12-10 Thread Riska Kurnianto
in staging or production env, You need to specify STATIC_ROOT in
settings.py and run "manage.py collectstatic".



On Mon, 10 Dec 2018, 10:28 pujiarahman  Hi all,
>
> i have instaled django in ubuntu,
> i have image and i put in folder (*img*), the locate is
>
> blog
> urls.py
> views.py
> admin.py
> --static
> -- blog
> -dist
> ---*img*
>
> When i load my browser The image is fine no problem, the problem is when,
> i config the settings.py  to :
>
> DEBUG = False
> ALLOWED_HOSTS = ['localhost', '27.0.0.1', 'xxx.xxx.xxx.xxx', '[::1]']
>
> the image can not found, but when i set Debug to True , the image come
> back normal.
> is there any miss in my config settings.py
>
> this my home.html
>
> {% load static %}
> 
> 
> 
> 
> 
> 
> 
>
> 
> NOC
> Member since Nov. 2018
> 
> 
> ..
>
>
> Regards
>
> Sidik
>
> --
> 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/7b30d6a2-c1e0-45fb-8722-3b38ed6fd062%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/CAG7yD2Lv-5cKTT1sr%3Dsqhj92DVoD6faooOfag%3DkBVob-qenb4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


pdf file generated using reportlab , getting saved as plain text

2018-12-10 Thread tasiftarikul
this is the first time i'm using reportlab. i copied the exact code from 
django documentation. 
https://docs.djangoproject.com/en/2.1/howto/outputting-pdf/. when i save 
the file its getting saved as plain text document (text/plain). the name 
remains the same hello.pdf.

p = canvas.Canvas(buffer)

in this line if i specify the name of file 'hello.pdf' instead of buffer 
and remove the buffer from the fileresponse method it works and 
automatically gets saved as pdf file, but i cannot prompt the user to save 
the file.



buffer = io.BytesIO()
# Create the PDF object, using the buffer as its "file."
p = canvas.Canvas(buffer)
print(type(p))
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
p.drawString(100, 100, "Hello world.")

# Close the PDF object cleanly, and we're done.
p.showPage()
p.save()
print(type(p))

# FileResponse sets the Content-Disposition header so that browsers
# present the option to save the file.
return FileResponse(buffer, as_attachment=True, filename='hello.pdf')

i tried specifying the content_type='application/pdf' on the code provided 
by django documentation but it still gets saved as plain text document. i'm 
guessing the File response cannot guess the type of file from the filename 
argument as mentioned in django documentation.
*class *FileResponse(*open_file*, *as_attachment=False*, *filename=''*, 
***kwargs)*

if open_file doesn’t have a name or if the name of open_file isn’t 
appropriate, provide a custom file name using the filename parameter.

The as_attachment and filename keywords argument were added. Also, 
FileResponse sets the Contentheaders if it can guess them.

 

If i use the code from 2.0 django documentation it works. is there a bug in 
the latest django documentation 2.1?
i installed all the dependencies according to this official link 
https://bitbucket.org/rptlab/reportlab/src/927995d54048767531a4ad4a0648e46064b0c4c7/README.txt?at=default&fileviewer=file-view-default
environment- ubuntu 18.04lts , pycharm, Python 3.5.6, reportlab 3.5.12.

-- 
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/d67b7502-0426-41da-a8fd-e793791a394b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django website

2018-12-10 Thread Riska Kurnianto
Really good to start with diagram, such as UML, theb class diagram, then
coding...

On Mon, 10 Dec 2018, 01:02 Kasper Laudrup  Hi Abiye,
>
> On 09/12/2018 09.01, Abiye Anabraba wrote:
> > Hello am Abiye,
> > Please I want to create a site like nnu.ng any idea no how to go about
> > this?. Thanks
> >
>
> Take a look here:
>
> https://docs.djangoproject.com/en/2.1/intro/
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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/357dfbac-3bd7-fe64-908a-0f4bf2ed0301%40stacktrace.dk
> .
> 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/CAG7yD2JSA7Bpyo0xtEGguWnpZKQyLPZQBU-06cvTiAeuL7bJyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: drop down multi checkbox with bootstraps selet

2018-12-10 Thread manikanta katikam
can u plese send this code 

On Saturday, March 18, 2017 at 10:28:07 PM UTC+5:30, ايهاب توفيق wrote:
>
> I am tring to create drop down checkbox with values from database   in my 
> templet using bootstrap select and form MultipleChoiceField like this 
>
>  
>
> Html
>
> select class="selectpicker" multiple>
>
> {% for topping in form.the_topping %}
>
> {{ topping.topping_id }}
>
>  
>
> {% endfor %}
>
> 
>
>  
>
> 
>
> $(document).ready(function() {
>
>   $('.selectpicker').selectpicker({
>
> style: 'btn-info',
>
> size: 4
>
> });
>
> });
>
> 
>
> Form.py
>
> *class *ProfileForm(forms.ModelForm):
> the_topping = 
> forms.ModelMultipleChoiceField(queryset=Topping.objects.all(), 
> required=*False*, widget=forms.CheckboxSelectMultiple)
>
> *class *Meta:
> model = Pizza
> exclude = [*'user'*]
>
>  
>
> the bootstrp working and the form is working but doesnot combined 
>
>  
>
> can any one help me PLS
>

-- 
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/d70d5caf-fc66-45a1-9558-582c2f033c28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


function get_form_kwargs() not being called

2018-12-10 Thread Simon A
 

I'm trying to pass a parameter from a redirect to the CreateView and to the 
form.

I have no problem retrieving the value from the redirect to the CreateView.

But my issue is when trying get the value to the form. I'm overriding 
get_form_kwargs function of my CreateView but when I try to do operations 
from that function, I'm not able to get any result. I tried to do a print 
but the print won't display anything.


*class NoteCreate(LoginRequiredMixin, CreateView):
login_url = 'login'
model = Note
form_class = NoteForm
success_url = reverse_lazy('note:list')

def get_form_kwargs(self):
kwargs = super(NoteCreate, self).get_form_kwargs()
kwargs.update({'file_id' : self.kwargs['file_id']})
print("im alivveeeEe!")
return** kwargs*

the print statement doesn't seem to be working. It does not show anything 
in the console.

I'm able to render the form with no errors in the console.

-- 
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/316c9add-4b15-4b94-a6b5-dbc3e1e908c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Multiple Forms in UpdateView

2018-12-10 Thread Lekan
Hello, is there a way to edit two update and save two forms from two 
different models with update view.. the issue is that i have two forms 
that i use in a single form format.now i want to write an update view 
for the it. how do i update two models in a updateView.

-- 
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/3516fb75-468d-4d32-86e2-1a98fb88ca97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django UpdateView and Createview

2018-12-10 Thread Sidnei Pereira
Hi,

I don't know if I got it right , but you want to add/update as many 
instance of Technologies as you want when creating/updating a Project, 
right? Like when you use an inline on Django's admin 

.

For that you could user Django Formsets 
. Here is 
simple gist for you to get a feeling of it:

https://gist.github.com/neara/6209563

An observation about your models, since you want *a Projetct to have many 
Technologies* you don't need a junction table. You could just user a 
ForeignKey model field on the TechnologyMaster model that refers to 
ProjectMaster model. The way you doing it know it's is actually a many to 
many relationship. For a better understanding of it in the context of how 
Django works with database modeling, see: 

https://docs.djangoproject.com/en/2.1/topics/db/models/#relationships

https://docs.djangoproject.com/en/2.1/topics/db/examples/


Em segunda-feira, 10 de dezembro de 2018 07:34:54 UTC-2, Rupam Hazra 
escreveu:
>
> Hi all,
>
> I know and understand how update view working but in my case how to 
> implement on my case.
>
> Please suggest.;
>
> On Sunday, 9 December 2018 23:13:04 UTC+5:30, Okware Aldo wrote:
>>
>> Ryan's suggestion should give you a starting point. 
>>
>> On Sun, Dec 9, 2018 at 3:43 PM Deepak Kumar  wrote:
>>
>>> On Sunday, December 9, 2018 at 6:21:55 AM UTC+5:30, Ryan Nowakowski 
>>> wrote:
>>> > Take a look at 
>>> https://docs.djangoproject.com/en/2.1/topics/class-based-views/generic-editing/
>>> > 
>>> > 
>>> > On December 7, 2018 7:09:25 AM CST, Rupam Hazra  
>>> wrote:
>>> > 
>>> > Hi,
>>> > 
>>> > 
>>> > I have working in a TaskManagement Sytem where i have project module 
>>> and technology module.
>>> > 
>>> > 
>>> > class ProjectMaster(models.Model):
>>> > name=models.CharField(max_length=255,blank=True,null=True)
>>> > description=models.CharField(max_length=255,blank=True,null=True)
>>> > is_agreement_sent=models.BooleanField(default=False)
>>> > is_invoice_create=models.BooleanField(default=False)
>>> > is_invoice_sent=models.BooleanField(default=False)
>>> > is_paid=models.BooleanField(default=False)
>>> > status=models.BooleanField(default=True)
>>> > is_deleted=models.BooleanField(default=False)
>>> > created_at=models.DateTimeField(auto_now_add=True)
>>> > created_by = models.ForeignKey(User, 
>>> on_delete=models.CASCADE,related_name='createdUser',blank=True,null=True)
>>> > updated_at=models.DateTimeField(auto_now_add=True)
>>> > updated_by=models.ForeignKey(User, on_delete=models.CASCADE, 
>>> related_name='UpdUser',blank=True,null=True)
>>> > #technology_master = models.ForeignKey(TechnologyMaster, 
>>> on_delete=models.CASCADE, related_name='technologies', )
>>> > 
>>> > def __str__(self):
>>> > return str(self.name)
>>> > class TechnologyMaster(models.Model):
>>> > #projectmaster = 
>>> models.ForeignKey(ProjectMaster,on_delete=models.CASCADE)
>>> > name=models.CharField(max_length=255,blank=True,null=True)
>>> > status = models.BooleanField(default=True)
>>> > is_deleted = models.BooleanField(default=False)
>>> > created_at = models.DateTimeField(auto_now_add=True)
>>> > created_by = models.ForeignKey(User, 
>>> on_delete=models.CASCADE,blank=True, null=True,related_name='created_by')
>>> > updated_at = models.DateTimeField(auto_now_add=True)
>>> > updated_by = models.ForeignKey(User, 
>>> on_delete=models.CASCADE,blank=True, null=True,related_name='updated_by')
>>> > def __str__(self):
>>> > return str(self.id)+'-'+ self.nameHere one functionality is 
>>> one project has multiple technologies so i have made one mapping table 
>>> belowclass ProjectTechnologyMapping(models.Model):
>>> > project_master = models.ForeignKey(ProjectMaster, 
>>> on_delete=models.CASCADE, related_name='projects')
>>> > technology_master = models.ForeignKey(TechnologyMaster, 
>>> on_delete=models.CASCADE, related_name='technologies')
>>> > status = models.BooleanField(default=True)
>>> > is_deleted = models.BooleanField(default=False)
>>> > created_at = models.DateTimeField(auto_now_add=True)
>>> > created_by = models.ForeignKey(User, 
>>> on_delete=models.CASCADE,blank=True,null=True,related_name='pro_tech_created_user')
>>> > updated_at = models.DateTimeField(auto_now_add=True)
>>> > updated_by = models.ForeignKey(User, 
>>> on_delete=models.CASCADE,blank=True,null=True,related_name='pro_tech_updated_user')
>>> > def __str__(self):
>>> > return str(self.id)So, my question is how add and update 
>>> using django createview,updateview (generic view) using templates.
>>>
>>> -- 
>>> 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

Re: Poor Performance for Form Rendering In Django 1.11

2018-12-10 Thread John Lehmann
Hi Simon, thanks for the response.

I am still hoping however for someone to explain to me why the default
renderer cannot handle my use case, such as that a few hundred inputs is
too many, or that I am doing something else improperly.  Surely this kind
of a change would not be made to the framework that would cause such an
unacceptable performance (500+ms added). Kind of disappointing to spend a
whole week upgrading only to end up wanting to downgrade again.

I think your idea is a good workaround to explore if I cannot get any
answers, and I appreciate it. I did briefly try to set this up by setting
the default_renderer = renderers.Jinja2, but ran into some problems so that
will take more looking into.



On Fri, Dec 7, 2018 at 10:39 AM Simon Charette  wrote:

> Hello John,
>
> Did you try switching to the Jinja2 form renderer[0] to see if it helps?
> I've not
> tried it myself but I heard it makes a significant difference.
>
> Cheers,
> Simon
>
> [0] https://docs.djangoproject.com/en/2.1/ref/forms/renderers/#jinja2
>
> Le vendredi 7 décembre 2018 08:30:48 UTC-5, John a écrit :
>>
>> My site  has a navbar with an advanced
>> search widget (beside the search field), which renders on every page. For
>> each request, a context_processor creates the form so it can be
>> available on that page in the navbar. This form has about a dozen selects
>> with a total of several hundred options. Most of those options are for the
>> currency and country selects, along with about 80 other options. There is
>> an even larger list for "stores" but it is loaded via AJAX so it should not
>> be a factor here.
>>
>> Performance was fine on Django 1.8, but after upgrading to 1.11 I noticed
>> with NewRelic that over 500 ms are now being used on my most frequent
>> request between the following:
>>
>>- Render/django/forms/widgets/select_option.html
>>- Render/django/forms/widgets/select.html
>>- Render/django/forms/widgets/attrs.html
>>
>> [image: xDE2A.png]
>>
>> This seems to be related to 1.11's change to Template-based Widget
>> Rendering  (docs
>> ),
>> however the only pages I could find talking about related problems were
>> about Django Toolbar which I do not run in production.
>>
>> I am and already using the Cached Template Loader (which is now default),
>> however I don't know if this helps here. I cannot easily cache this form
>> because as you can see in the code, I set a number of defaults based on the
>> request.
>>
>> Why is my form suffering so badly from this change? Eliminating two of
>> the bigger selects helps, but surely several hundred options should not
>> take this long to render so it seems to me there is an underlying problem
>> that the quantity is merely exacerbating.
>>
>> Here are links to to code for the full form and html. (I will include
>> snippets in the question later when we identify the problem, for future
>> readers).
>>
>>- Search Form
>>
>> 
>>- Search HTML
>>
>>- Live Site 
>>
>> Thank you in advance for your help!
>>
> --
> 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/uhe7ExBJoxg/unsubscribe.
> To unsubscribe from this group and all its topics, 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/b4a2a1d1-63e2-4a14-a5fa-2e75a018dadf%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/CANRc4UNrqAyqHjqbJxJpPG-TPWUJmxeQ%2BQFOkJr%2BBFvCQVGqDQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: help

2018-12-10 Thread Jason
that is an invalid URL you have in the browser address bar.  you don't need 
the curly braces or dict format.

just simply 127.0.0.1:8000/todo/dailytask

-- 
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/d353ae63-c416-4d0c-af50-2061006d723b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Poor Performance for Form Rendering In Django 1.11

2018-12-10 Thread James Bennett
On Mon, Dec 10, 2018 at 5:31 AM John Lehmann  wrote:

> I am still hoping however for someone to explain to me why the default
> renderer cannot handle my use case, such as that a few hundred inputs is
> too many, or that I am doing something else improperly.  Surely this kind
> of a change would not be made to the framework that would cause such an
> unacceptable performance (500+ms added). Kind of disappointing to spend a
> whole week upgrading only to end up wanting to downgrade again.
>

The Django template language is not really optimized for speed of
rendering. Even with a caching loader, rendering a template hundreds of
times will be an expensive enough operation to show up in your profiling.

The solutions are to use something faster (Jinja) if you absolutely must be
rendering hundreds of things, or find a way to make the form more efficient
(generally, when a form has hundreds of options to display in a select,
that's a sign of issues with the design of the form).

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


Issue with model method

2018-12-10 Thread Felix Lazaro Carbobonell
 

Good day to everyone.

 

I have defined a model method wich is called on a template (DTL) and the
result is None when I test the URI with selenium. Normal attributes from the
model are displayed correctly.

But when I test the same URI with the Django test client it works as
expected and the result from the model method is correctly rendered in the
template.

 

Could you please help me with this issue.

 

Best regards,

Felix Carbonell.

-- 
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/018e01d49091%24608e8e80%2421abab80%24%40epepm.cupet.cu.
For more options, visit https://groups.google.com/d/optout.


Re: Poor Performance for Form Rendering In Django 1.11

2018-12-10 Thread John Lehmann
Hi James,

Thank you for the input!

So my takeaway from what you are saying is that no one is running a
production site with a Django select field to render a country or currency
option (e.g., django-countries or django-money), because either of these
would have well over a hundred entries (and my form happens to have both).
Instead they would be loading these options via AJAX or using a different
widget all together like an auto-complete.  (I get it that a long list is
not the best UX but that's a bit of a different discussion).

It seems like a regression of this magnitude should be called out in the
Django documentation for the default rendering option?  I'm also surprised
neither of those mainstream libraries would mention something about this.
Adding 500+ms isn't in the realm of "tweaking" performance, for most
serious sites it would be a complete fail.  So I guess I'm just a little
skeptical that the real answer here is that I shouldn't expect this to work
anyway. I feel like this kind of change would have affected a lot of other
folks in similar significant fashion, which makes me think there is
something else going on (some other kind of boneheaded thing I may be
doing).

thanks,
John




On Mon, Dec 10, 2018 at 7:47 AM James Bennett  wrote:

> On Mon, Dec 10, 2018 at 5:31 AM John Lehmann 
> wrote:
>
>> I am still hoping however for someone to explain to me why the default
>> renderer cannot handle my use case, such as that a few hundred inputs is
>> too many, or that I am doing something else improperly.  Surely this kind
>> of a change would not be made to the framework that would cause such an
>> unacceptable performance (500+ms added). Kind of disappointing to spend a
>> whole week upgrading only to end up wanting to downgrade again.
>>
>
> The Django template language is not really optimized for speed of
> rendering. Even with a caching loader, rendering a template hundreds of
> times will be an expensive enough operation to show up in your profiling.
>
> The solutions are to use something faster (Jinja) if you absolutely must
> be rendering hundreds of things, or find a way to make the form more
> efficient (generally, when a form has hundreds of options to display in a
> select, that's a sign of issues with the design of the form).
>
> --
> 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/uhe7ExBJoxg/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAL13Cg9amLPan9-pj%2BHpHc7vns6_5EJcvNHvF0VPakf651%3DT1g%40mail.gmail.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/CANRc4UPMBqpOypDekUAsPbU9KLf0DL%2BAEghAZsJo30uUhyYXJQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django UpdateView and Createview

2018-12-10 Thread Ryan Nowakowski
Hrrmmm... that documentation link should've answered most of your
questions.  It would be easier to help you if you can say specifically
what you're confused about.

On Mon, Dec 10, 2018 at 01:34:53AM -0800, Rupam Hazra wrote:
> Hi all,
> 
> I know and understand how update view working but in my case how to 
> implement on my case.
> 
> Please suggest.;
> 
> On Sunday, 9 December 2018 23:13:04 UTC+5:30, Okware Aldo wrote:
> >
> > Ryan's suggestion should give you a starting point. 
> >
> > On Sun, Dec 9, 2018 at 3:43 PM Deepak Kumar  > > wrote:
> >
> >> On Sunday, December 9, 2018 at 6:21:55 AM UTC+5:30, Ryan Nowakowski wrote:
> >> > Take a look at 
> >> https://docs.djangoproject.com/en/2.1/topics/class-based-views/generic-editing/
> >> > 
> >> > 
> >> > On December 7, 2018 7:09:25 AM CST, Rupam Hazra  
> >> wrote:
> >> > 
> >> > Hi,
> >> > 
> >> > 
> >> > I have working in a TaskManagement Sytem where i have project module 
> >> and technology module.
> >> > 
> >> > 
> >> > class ProjectMaster(models.Model):
> >> > name=models.CharField(max_length=255,blank=True,null=True)
> >> > description=models.CharField(max_length=255,blank=True,null=True)
> >> > is_agreement_sent=models.BooleanField(default=False)
> >> > is_invoice_create=models.BooleanField(default=False)
> >> > is_invoice_sent=models.BooleanField(default=False)
> >> > is_paid=models.BooleanField(default=False)
> >> > status=models.BooleanField(default=True)
> >> > is_deleted=models.BooleanField(default=False)
> >> > created_at=models.DateTimeField(auto_now_add=True)
> >> > created_by = models.ForeignKey(User, 
> >> on_delete=models.CASCADE,related_name='createdUser',blank=True,null=True)
> >> > updated_at=models.DateTimeField(auto_now_add=True)
> >> > updated_by=models.ForeignKey(User, on_delete=models.CASCADE, 
> >> related_name='UpdUser',blank=True,null=True)
> >> > #technology_master = models.ForeignKey(TechnologyMaster, 
> >> on_delete=models.CASCADE, related_name='technologies', )
> >> > 
> >> > def __str__(self):
> >> > return str(self.name)
> >> > class TechnologyMaster(models.Model):
> >> > #projectmaster = 
> >> models.ForeignKey(ProjectMaster,on_delete=models.CASCADE)
> >> > name=models.CharField(max_length=255,blank=True,null=True)
> >> > status = models.BooleanField(default=True)
> >> > is_deleted = models.BooleanField(default=False)
> >> > created_at = models.DateTimeField(auto_now_add=True)
> >> > created_by = models.ForeignKey(User, 
> >> on_delete=models.CASCADE,blank=True, null=True,related_name='created_by')
> >> > updated_at = models.DateTimeField(auto_now_add=True)
> >> > updated_by = models.ForeignKey(User, 
> >> on_delete=models.CASCADE,blank=True, null=True,related_name='updated_by')
> >> > def __str__(self):
> >> > return str(self.id)+'-'+ self.nameHere one functionality is 
> >> one project has multiple technologies so i have made one mapping table 
> >> belowclass ProjectTechnologyMapping(models.Model):
> >> > project_master = models.ForeignKey(ProjectMaster, 
> >> on_delete=models.CASCADE, related_name='projects')
> >> > technology_master = models.ForeignKey(TechnologyMaster, 
> >> on_delete=models.CASCADE, related_name='technologies')
> >> > status = models.BooleanField(default=True)
> >> > is_deleted = models.BooleanField(default=False)
> >> > created_at = models.DateTimeField(auto_now_add=True)
> >> > created_by = models.ForeignKey(User, 
> >> on_delete=models.CASCADE,blank=True,null=True,related_name='pro_tech_created_user')
> >> > updated_at = models.DateTimeField(auto_now_add=True)
> >> > updated_by = models.ForeignKey(User, 
> >> on_delete=models.CASCADE,blank=True,null=True,related_name='pro_tech_updated_user')
> >> > def __str__(self):
> >> > return str(self.id)So, my question is how add and update using 
> >> django createview,updateview (generic view) using templates.
> >>
> >> -- 
> >> 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/b0be82da-dca5-4594-9f22-e0c3323adc3b%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-user

Re: Poor Performance for Form Rendering In Django 1.11

2018-12-10 Thread James Bennett
On Mon, Dec 10, 2018 at 6:29 AM John Lehmann  wrote:

> So my takeaway from what you are saying is that no one is running a
> production site with a Django select field to render a country or currency
> option (e.g., django-countries or django-money), because either of these
> would have well over a hundred entries (and my form happens to have both).
> Instead they would be loading these options via AJAX or using a different
> widget all together like an auto-complete.  (I get it that a long list is
> not the best UX but that's a bit of a different discussion).
>

Have you profiled a country select on its own?

Your original post suggested you had multiple large (hundreds of options)
selects in a single form that you were rendering. Whether any specific
individual select in the form is the sole culprit, or whether it's the
combination of them, is something you still haven't pinned down, and it's a
bit combative to jump to "nobody must have a country select" from that.

In general, a select with a large set of options is going to be slower to
render. It may turn out that this has nothing whatsoever to do with your
problem, but we don't have enough information to precisely diagnose your
problem; all we can do here is give you general advice like "avoid
rendering a template hundreds of times if you can, or use a
faster-rendering template option if you can't".

-- 
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/CAL13Cg9YnOwGYATe%3DBpHBGEoULeNJ8VngJsPp3LQfGR1AJvxHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Poor Performance for Form Rendering In Django 1.11

2018-12-10 Thread John
Yes, the form has about a dozen selects, with two in particular being 
larger - the country and the currency fields - that probably have a couple 
hundred options each.  I have since removed those two fields which leaves 
about 10 selects with about 80 options total.  While these numbers 
fluctuate, the 12 field form was taking a little over 750ms, and the new 
form with 10 fields totals 375ms. So the two larger fields accounted for 
about half the time, but even the reduced form is still a major problem.

Regarding the reduced version, I cannot say how much the performance issue 
relates to having 10 selects, or to have 80 options. But it seems like 
375ms is an unreasonable amount of time for this amount of work.  (Just as 
it seems unreasonable to spend 400ms drawing those other two fields).

You can see the form by visiting the site  
and clicking on "options" next to the search bar.

I'm sorry and didn't mean to sound combative, was trying to point out that 
if this is the performance we expect for the default renderer, then I would 
have expected to see a lot more people reacting to 1.11.  Which is why I 
believe something else must be going on.




[image: Screen Shot 2018-12-10 at 8.59.32 AM.png]




On Monday, December 10, 2018 at 8:40:51 AM UTC-6, James Bennett wrote:
>
> On Mon, Dec 10, 2018 at 6:29 AM John Lehmann  > wrote:
>
>> So my takeaway from what you are saying is that no one is running a 
>> production site with a Django select field to render a country or currency 
>> option (e.g., django-countries or django-money), because either of these 
>> would have well over a hundred entries (and my form happens to have both).  
>> Instead they would be loading these options via AJAX or using a different 
>> widget all together like an auto-complete.  (I get it that a long list is 
>> not the best UX but that's a bit of a different discussion).
>>
>
> Have you profiled a country select on its own?
>
> Your original post suggested you had multiple large (hundreds of options) 
> selects in a single form that you were rendering. Whether any specific 
> individual select in the form is the sole culprit, or whether it's the 
> combination of them, is something you still haven't pinned down, and it's a 
> bit combative to jump to "nobody must have a country select" from that.
>
> In general, a select with a large set of options is going to be slower to 
> render. It may turn out that this has nothing whatsoever to do with your 
> problem, but we don't have enough information to precisely diagnose your 
> problem; all we can do here is give you general advice like "avoid 
> rendering a template hundreds of times if you can, or use a 
> faster-rendering template option if you can't".
>

-- 
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/7e723ec8-be37-49cf-969e-5b484e3e5b65%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Poor Performance for Form Rendering In Django 1.11

2018-12-10 Thread Matthew Pava
I vaguely remember having this issue when I moved to Django 1.11.  It was 
frustrating.  I have thus far refused to move over to Jinja, and I just use 
autocompletes for my large select widgets.

There is also the possibility of using template fragment caching.  Wrap the 
select in a cache block, and it will loaded into memory once.  See 
https://docs.djangoproject.com/en/1.11/topics/cache/#template-fragment-caching.





From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of John
Sent: Monday, December 10, 2018 9:19 AM
To: Django users
Subject: Re: Poor Performance for Form Rendering In Django 1.11

Yes, the form has about a dozen selects, with two in particular being larger - 
the country and the currency fields - that probably have a couple hundred 
options each.  I have since removed those two fields which leaves about 10 
selects with about 80 options total.  While these numbers fluctuate, the 12 
field form was taking a little over 750ms, and the new form with 10 fields 
totals 375ms. So the two larger fields accounted for about half the time, but 
even the reduced form is still a major problem.

Regarding the reduced version, I cannot say how much the performance issue 
relates to having 10 selects, or to have 80 options. But it seems like 375ms is 
an unreasonable amount of time for this amount of work.  (Just as it seems 
unreasonable to spend 400ms drawing those other two fields).

You can see the form by visiting the site and 
clicking on "options" next to the search bar.

I'm sorry and didn't mean to sound combative, was trying to point out that if 
this is the performance we expect for the default renderer, then I would have 
expected to see a lot more people reacting to 1.11.  Which is why I believe 
something else must be going on.





[Screen Shot 2018-12-10 at 8.59.32 AM.png]




On Monday, December 10, 2018 at 8:40:51 AM UTC-6, James Bennett wrote:
On Mon, Dec 10, 2018 at 6:29 AM John Lehmann > 
wrote:
So my takeaway from what you are saying is that no one is running a production 
site with a Django select field to render a country or currency option (e.g., 
django-countries or django-money), because either of these would have well over 
a hundred entries (and my form happens to have both).  Instead they would be 
loading these options via AJAX or using a different widget all together like an 
auto-complete.  (I get it that a long list is not the best UX but that's a bit 
of a different discussion).

Have you profiled a country select on its own?

Your original post suggested you had multiple large (hundreds of options) 
selects in a single form that you were rendering. Whether any specific 
individual select in the form is the sole culprit, or whether it's the 
combination of them, is something you still haven't pinned down, and it's a bit 
combative to jump to "nobody must have a country select" from that.

In general, a select with a large set of options is going to be slower to 
render. It may turn out that this has nothing whatsoever to do with your 
problem, but we don't have enough information to precisely diagnose your 
problem; all we can do here is give you general advice like "avoid rendering a 
template hundreds of times if you can, or use a faster-rendering template 
option if you can't".
--
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/7e723ec8-be37-49cf-969e-5b484e3e5b65%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/23ed36f946a143f7bffa7128832d9686%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Using reflection with Django models to determine module containing the choices?

2018-12-10 Thread Stodge
Let's say I take the following code from the Django documentatation:


class Student(models.Model):
FRESHMAN = 'FR'
SOPHOMORE = 'SO'
JUNIOR = 'JR'
SENIOR = 'SR'
YEAR_IN_SCHOOL_CHOICES = (
(FRESHMAN, 'Freshman'),
(SOPHOMORE, 'Sophomore'),
(JUNIOR, 'Junior'),
(SENIOR, 'Senior'),
)
year_in_school = models.CharField(
max_length=2,
choices=YEAR_IN_SCHOOL_CHOICES,
default=FRESHMAN,
)


But instead I want to do:

from student_app import choices
class Student(models.Model):
year_in_school = models.CharField(
max_length=2,
choices=choices.YEAR_IN_SCHOOL_CHOICES,
default=choices.FRESHMAN,
)


Is there anyway using reflection to determine which module the choices are 
imported from?

For example:

field = Student._meta.fields.get_field_by_name('year_in_school')
choices_source = some_clever_function(field)
print("Choices imported from %s." % choices_source)

I want the output to be:

Choices imported from student_app.

Obviously the clever function does not exist but hopefully clarifies what 
I'm trying to do.

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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/78f7dcc2-c822-42cc-a06a-860ae080e5b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Cannot get this ModelForm view to save to the db, what am I doing wrong please

2018-12-10 Thread MikeKJ
 

Cannot seem to get .save() to write to the db

This is the model


class Customer(models.Model):
email = models.EmailField()
postcode = models.CharField(max_length=10)
def __unicode__(self):
return self.email
def save(self):
self.postcode=upper(self.postcode)
super(Customer, self).save()
 

This is the view:


class RegisterForm(ModelForm):
class Meta:
model = Customer

def register(request):
form = RegisterForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
postcode = form.cleaned_data['postcode']
postcode = upper(postcode)
try:
user = 
Customer.objects.all().filter(email=email).filter(postcode=postcode)[:1]
if user:
error = "You have already registered this email address and 
postcode, please login."
return render_to_response("customer/register_form.html", 
{'error': error, 'form': form, 'content': 
content,},context_instance=RequestContext(request))
except Customer.DoesNotExist:
cust_obj = Customer(email=email, postcode=postcode)
cust_obj.save()
return HttpResponseRedirect('/registration-thankyou/')

Also tried

new_user = form.save(commit=False)
new_user.save()

It isn't throwing any errors just not saving to the table 

Cheers for any insight/help

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


Re: Using reflection with Django models to determine module containing the choices?

2018-12-10 Thread Simon Charette
Given choices are defined at the module level I guess you could
iterate over objects defined in each `sys.modules` (or the ones
likely to define choices) and use the `is` operator to compare all
of them to the field choices.

This will perform badly and shouldn't be used for anything else
than one off debugging reflection though.

Best,
Simon

Le lundi 10 décembre 2018 10:33:35 UTC-5, Stodge a écrit :
>
> Let's say I take the following code from the Django documentatation:
>
>
> class Student(models.Model):
> FRESHMAN = 'FR'
> SOPHOMORE = 'SO'
> JUNIOR = 'JR'
> SENIOR = 'SR'
> YEAR_IN_SCHOOL_CHOICES = (
> (FRESHMAN, 'Freshman'),
> (SOPHOMORE, 'Sophomore'),
> (JUNIOR, 'Junior'),
> (SENIOR, 'Senior'),
> )
> year_in_school = models.CharField(
> max_length=2,
> choices=YEAR_IN_SCHOOL_CHOICES,
> default=FRESHMAN,
> )
>
>
> But instead I want to do:
>
> from student_app import choices
> class Student(models.Model):
> year_in_school = models.CharField(
> max_length=2,
> choices=choices.YEAR_IN_SCHOOL_CHOICES,
> default=choices.FRESHMAN,
> )
>
>
> Is there anyway using reflection to determine which module the choices are 
> imported from?
>
> For example:
>
> field = Student._meta.fields.get_field_by_name('year_in_school')
> choices_source = some_clever_function(field)
> print("Choices imported from %s." % choices_source)
>
> I want the output to be:
>
> Choices imported from student_app.
>
> Obviously the clever function does not exist but hopefully clarifies what 
> I'm trying to do.
>
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4e74fd89-715a-4b93-bbe9-7d0bcd50fe98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Cannot get this ModelForm view to save to the db, what am I doing wrong please

2018-12-10 Thread Matthew Pava
It’s hard to tell with some of the spacing in your email.  Python cares deeply 
about spacing.

When initializing a form, I typically do it as so:
form = RegisterForm(request.POST or None)

Also, the save method on the model has several arguments that you are not 
passing around.

def save(self, *args, **kwargs):

self.postcode = self.postcode.upper()
super(Customer, self).save(*args, **kwargs)

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of MikeKJ
Sent: Monday, December 10, 2018 10:41 AM
To: Django users
Subject: Cannot get this ModelForm view to save to the db, what am I doing 
wrong please


Cannot seem to get .save() to write to the db

This is the model



class Customer(models.Model):

email = models.EmailField()

postcode = models.CharField(max_length=10)

def __unicode__(self):

return self.email

def save(self):

self.postcode=upper(self.postcode)

super(Customer, self).save()


This is the view:

class RegisterForm(ModelForm):

class Meta:

model = Customer



def register(request):

form = RegisterForm(request.POST)

if form.is_valid():

email = form.cleaned_data['email']

postcode = form.cleaned_data['postcode']

postcode = upper(postcode)

try:

user = 
Customer.objects.all().filter(email=email).filter(postcode=postcode)[:1]

if user:

error = "You have already registered this email address and 
postcode, please login."

return render_to_response("customer/register_form.html", 
{'error': error, 'form': form, 'content': 
content,},context_instance=RequestContext(request))

except Customer.DoesNotExist:

cust_obj = Customer(email=email, postcode=postcode)

cust_obj.save()

return HttpResponseRedirect('/registration-thankyou/')

Also tried

new_user = form.save(commit=False)

new_user.save()

It isn't throwing any errors just not saving to the table

Cheers for any insight/help
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com.
To post to this group, send email to 
django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b55ba86d-65dd-4c33-9144-4b9a5cf15bcc%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/48cdf86ecf1240a99d940d4295ba0d34%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Order of migration dependencies when running makemigrations from scratch

2018-12-10 Thread Dakota Hawkins
Thanks again, Simon!

Filed 30029 

On Sunday, December 9, 2018 at 11:28:54 PM UTC-5, Simon Charette wrote:
>
> Hello Dakota,
>
> From looking at the autodetector code in charge of generating these 
> lists[0]
> and the loader code in charge of resolving them[1][2] I'm pretty confident 
> their order
> doesn't carry any meaning.
>
> They should have been defined as a set from the beginning.
>
> Cheers,
> Simon
>
> [0] 
> https://github.com/django/django/blob/c5568340a525ab9c6898ed02c257394cc47285d7/django/db/migrations/autodetector.py#L274-L323
> [1] 
> https://github.com/django/django/blob/c5568340a525ab9c6898ed02c257394cc47285d7/django/db/migrations/loader.py#L176-L184
> [2] 
> https://github.com/django/django/blob/c5568340a525ab9c6898ed02c257394cc47285d7/django/db/migrations/graph.py#L85-L120
>
> Le dimanche 9 décembre 2018 19:09:42 UTC-5, Dakota Hawkins a écrit :
>>
>> Hi Simon!
>>
>> Thanks for the information, I'll submit a feature request! I dug through 
>> the code a bit and the one thing that concerned me a little was the 
>> possibility that sorting might have to account for dependencies between 
>> your app's dependencies. For example if app2's migration specified that it 
>> must run before auth's migration, does that mean app1's migration must 
>> appear before auth's or should that be sorted out by a different mechanism?
>>
>> Thanks,
>>
>> Dakota
>>
>> On Friday, December 7, 2018 at 7:42:09 AM UTC-5, Simon Charette wrote:
>>>
>>> Hello Dakota,
>>>
>>> Migration.dependencies should really have been defined as a set from the 
>>> start
>>> as Django doesn't care about their order anyway.
>>>
>>> I unfortunately cannot provide a work around but I suggest you submit an
>>> improvement/cleanup ticket to make the order deterministic. It should be
>>> a simple matter of using sorted in MigrationWriter.as_string[0].
>>>
>>> Cheers,
>>> Simon
>>>
>>> [0] 
>>> https://github.com/django/django/blob/79c196cfb287893aadc6b0e74603ffde1512170e/django/db/migrations/writer.py#L156-L164
>>>
>>> Le vendredi 7 décembre 2018 00:51:58 UTC-5, Dakota Hawkins a écrit :

 We haven't really deployed yet, so generally to make migrations we're 
 deleting existing migration files and re-running makemigrations.

 We have two apps, and one of them depends on the other as well as 
 django.contrib.auth. In that app's migrations the dependencies often swap 
 order seemingly indeterminately.

 [image: migrations.png]
 The resulting migration includes either:

 class Migration(migrations.Migration):
 initial = True
 dependencies = [
 ('auth', '0009_alter_user_last_name_max_length'),
 ('app2', '0001_initial'),
 ]
 ...


 or:

 class Migration(migrations.Migration):
 initial = True
 dependencies = [
 ('app2', '0001_initial'),
 ('auth', '0009_alter_user_last_name_max_length'),
 ]
 ...


 and it seems to switch back and forth with nearly every run.

 Does anybody know why, or how to nail down the order? It doesn't seem 
 to make a technical difference, but I'd like to avoid the churn/noise in 
 our repo.

>>>

-- 
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/339162ef-371e-4ee1-8c96-2ed1888d8eff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to transfer django projects from one pc to another

2018-12-10 Thread computer engineering Forum
I want to change my pc but i fear i wont be able to access the projects

-- 
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/72f991a7-4024-4a37-80f5-5f5604c7a391%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


wsgi_module not found on windows

2018-12-10 Thread mostafa .H


I asked a question in this StackOverflow question 
,
 
Please take a look and if you're able to answer it please help me.


this is the question for ones who don't access to StackOverflow:


After installing the *mod_wsgi* with pip correctly, and inserted its config 
related stuff to the *http.conf (apache)*. The wsgi_module was loaded 
successfully as shown in the log below:

*[Mon Dec 10 10:39:39.048697 2018] [wsgi:info] [pid 16708:tid 692]* mod_wsgi 
(pid=16708): Python home 
c:/users/.../appdata/local/programs/python/python37.

*[Mon Dec 10 10:39:39.048697 2018] [wsgi:info] [pid 16708:tid 692]* mod_wsgi 
(pid=16708): Initializing Python.

*[Mon Dec 10 10:39:39.081683 2018] [wsgi:info] [pid 16708:tid 692]* mod_wsgi 
(pid=16708): Attach interpreter ''.

*[Mon Dec 10 10:39:39.084682 2018] [wsgi:info] [pid 16708:tid 692]* mod_wsgi 
(pid=16708): Adding 'E:/projects/python/...' to path.

*[Mon Dec 10 10:39:39.089662 2018] [wsgi:info] [pid 16708:tid 692]* mod_wsgi 
(pid=16708): Imported 'mod_wsgi'.

But at the apache modules, the wsgi_module says *No module file* as shown 
in the picture below:

[image: enter image description here] 

And when I click on the *wsgi_module*, this output is displayed:

There is 'LoadModule wsgi_module modules/mod_wsgi.so' line in httpd.conf 
file but there no 'mod_wsgi.so' file in apachex.y.z/modules/ directory.

It is my http.conf lines which are associated with the mod_wsgi:


LoadFile 
"c:/users/.../appdata/local/programs/python/python37/python37.dll"LoadModule 
wsgi_module 
"c:/users/.../appdata/local/programs/python/python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"WSGIPythonHome
 "c:/users/.../appdata/local/programs/python/python37"WSGIPythonPath 
"E:/projects/python/..."WSGIScriptAlias /scripts 
"E:/projects/python/.../.../wsgi.py"
DocumentRoot "E:\\projects\\python\\...\\...\\..."

Allow From all

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options +Indexes +FollowSymLinks +Multiviews +ExecCGI

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   AllowOverride FileInfo AuthConfig Limit
#
AllowOverride all
Allow From all

#
# Controls who can get stuff from this server.
#
#   onlineoffline tag - don't remove
Require local

-- 
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/7775a8fc-0a19-40fd-ae2b-3b50e561dc41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to transfer django projects from one pc to another

2018-12-10 Thread Swetank Subham Roy
1. Make requirement file let's say requirement.txt using pip freeze
command, which keep records of packages used in the project.
2. Make a copy of project folder to the new machine.
3. Create virtual environment on new machine.
4. Activate and install package from requirement.txt file to the virtual
environment.
5. Configure database and other settings in settings.py of project.
6. Run makemigrations followed by migrate command.
7. Run run server command.

All done.

On Tue 11 Dec, 2018, 12:43 AM computer engineering Forum <
robinsoncheg...@gmail.com wrote:

> I want to change my pc but i fear i wont be able to access the projects
>
> --
> 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/72f991a7-4024-4a37-80f5-5f5604c7a391%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/CADQ%3Ddpodi2p-soGdTQh%2Bd42bM24d15O9%2BvPTzQVTHgRNe%2BiCfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Manage static files using Jinja2

2018-12-10 Thread miguel . yurivilca
I am using the documentation to learn Django. When I started creating 
static files, I started to get problems. I am using 
this: https://docs.djangoproject.com/en/2.1/howto/static-files/ but I think 
it is using Django template engine. How can I fix this problem?

Does every static file needs a url?

Thank you.

-- 
La información contenida en este e-mail y sus anexos es confidencial, 
privilegiada y está dirigida exclusivamente a su destinatario, en 
consecuencia, solo puede ser utilizada por aquel. Si usted no es el 
destinatario original, no deberá examinar, usar, copiar o distribuir este 
mensaje o la información que contiene. Si lo recibe por error, por favor 
reenvíelo a la persona que se lo envió y elimínelo. Cualquier retención o 
uso total o parcial no autorizada de este mensaje está estrictamente 
prohibida y sancionada por ley.

-- 
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/48ff25dd-f227-4984-82f4-26dc0c60e948%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to transfer django projects from one pc to another

2018-12-10 Thread Simon A
if you are really lazy, you can just zip your whole project. then transfer 
to another machine.

I transfer my projects from work (using windows) to home (using ubuntu) 
then vice versa. I only had to manually install the necessary packages will 
be notified to you when you need to get them installed when you try to run 
the server.

Also if you be using a different set of database, then that's another set 
of configuration.

On Tuesday, December 11, 2018 at 3:14:07 AM UTC+8, computer engineering 
Forum wrote:
>
> I want to change my pc but i fear i wont be able to access the projects
>

-- 
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/c3d2c4aa-59ab-4369-a061-c8ee2e88fcfb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to transfer django projects from one pc to another

2018-12-10 Thread Mike Dewhirst

On 11/12/2018 12:03 PM, Simon A wrote:
On Tuesday, December 11, 2018 at 3:14:07 AM UTC+8, computer 
engineering Forum wrote:


I want to change my pc but i fear i wont be able to access the
projects



I would assume my new pc is going to fail five minutes after I 
successfully transfer projects. Therefore I suggest that you start from 
scratch on the new pc with that in mind.


It (for me) involves ...

- a repository for each project

- a set of scripts for dumping various Postgres databases

- another set of scripts for dropping/creating/loading various databases 
from dump files


- a backup facility

- never manually installing software (if possible) but rather writing a 
script to do the installing. After running the script to install 
whatever I then comment out that line. Then for the inevitable 
replacement machine if I have backed up that script I only need to 
uncomment all (or most) lines and hey presto - a good start. I also keep 
comments in that install script to jog my memory to do stuff.


A new machine is an opportunity to improve your systems.

ymmv

--
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/8f1c7cbb-a3f8-e236-c949-a07bfea6051b%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Using reflection with Django models to determine module containing the choices?

2018-12-10 Thread Stodge
Thanks Simon. It's for an offline tool so high performance isn't the top 
priority.

On Monday, 10 December 2018 11:56:53 UTC-5, Simon Charette wrote:
>
> Given choices are defined at the module level I guess you could
> iterate over objects defined in each `sys.modules` (or the ones
> likely to define choices) and use the `is` operator to compare all
> of them to the field choices.
>
> This will perform badly and shouldn't be used for anything else
> than one off debugging reflection though.
>
> Best,
> Simon
>
> Le lundi 10 décembre 2018 10:33:35 UTC-5, Stodge a écrit :
>>
>> Let's say I take the following code from the Django documentatation:
>>
>>
>> class Student(models.Model):
>> FRESHMAN = 'FR'
>> SOPHOMORE = 'SO'
>> JUNIOR = 'JR'
>> SENIOR = 'SR'
>> YEAR_IN_SCHOOL_CHOICES = (
>> (FRESHMAN, 'Freshman'),
>> (SOPHOMORE, 'Sophomore'),
>> (JUNIOR, 'Junior'),
>> (SENIOR, 'Senior'),
>> )
>> year_in_school = models.CharField(
>> max_length=2,
>> choices=YEAR_IN_SCHOOL_CHOICES,
>> default=FRESHMAN,
>> )
>>
>>
>> But instead I want to do:
>>
>> from student_app import choices
>> class Student(models.Model):
>> year_in_school = models.CharField(
>> max_length=2,
>> choices=choices.YEAR_IN_SCHOOL_CHOICES,
>> default=choices.FRESHMAN,
>> )
>>
>>
>> Is there anyway using reflection to determine which module the choices 
>> are imported from?
>>
>> For example:
>>
>> field = Student._meta.fields.get_field_by_name('year_in_school')
>> choices_source = some_clever_function(field)
>> print("Choices imported from %s." % choices_source)
>>
>> I want the output to be:
>>
>> Choices imported from student_app.
>>
>> Obviously the clever function does not exist but hopefully clarifies what 
>> I'm trying to do.
>>
>> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8293ea73-1eae-4dcf-880a-64c55f051a12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problems from writing test cases.

2018-12-10 Thread ANi
Hello,
I am now trying to write test cases for my project, but I find some 
problems.

1.


class FirstTest(TestCase):

@classmethod
def setUpTestData(cls):
   User.objects.create(username = 'johndoe', password = 
'goodtobehere123')
   ...

def test_case_one(self):
   user = User.objects.get(pk=1)
   # some assertions here

   ...

class SecondTest(TestCase):

@classmethod
def setUpTestData(cls):
User.objects.create(username = 'janedoe', password = 
'nicetobethere456')

def test_case_one(self):
   user = User.objects.get(pk=1)
   # some assertions here

   ...
   

If I run all the tests together, I can pass the FirstTest while getting 
error of "django.contrib.auth.models.DoesNotExist: User matching query does 
not exist." on the SecondTest.
If I run two test cases separately, all tests are passed.
Then solved it by changing it into this:


class FirstTest(TestCase):

@classmethod
def setUpTestData(cls):
cls.user = User.objects.create(username = 'johndoe', password = 
'goodtobehere123')
...

def test_case_one(self):
   self.assertEqual(self.user.somefunc(), something)
   # some assertions here

   ...

class SecondTest(TestCase):

@classmethod
def setUpTestData(cls):
   cls.user = User.objects.create(username = 'janedoe', password = 
'nicetobethere456')
   ...

def test_case_one(self):
   self.assertEqual(self.user.somefunc(), something)
   # some assertions here

   ...



However I don't know why.?


2.

class ViewTest(TestCase):
 
@classmethod
def setUpTestData(cls):
cls.user = User.objects.create(username = 'johndoe', password = 
'goodtobehere123')
...

 def setUp(self):
 self.item = Item.objects.create(
 category = 1,
 item_content = 'content content',
 )


 def test_item_update(self):
 # the view will update the item and return HTTP status code 200.
 # if the item is not exist, raise Http404  
 self.c = Client() 
 resp = self.c.post(
reverse('update_item', kwargs={"pk":self.item.pk}),
data = {
"category": 2,
"content": "item content",
 }
 )

 self.assertEqual(resp.status_code, 200)
 self.assertEqual(self.item.category, 2)

 def test_item_delete(self):  
 # the view will delete the item and return HTTP status code 200.
 # if the item is not exist, raise Http404  
 self.c = Client() 
 resp = self.c.post(
reverse('delete_item'),
data = {
"pk": self.item.pk
 }
 )

 self.assertEqual(resp.status_code, 200)
  



I got " AssertionError: 1 != 2 ". for test_item_update()
and "AssertionError: 404 != 200". for test_item_delete()

I think it is reasonable but obviously I misunderstand something. 

Thank you. I will be very happy if you want to help me >___<



-- 
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/f1f9855a-3461-45a1-bdee-2ec901a7f718%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems from writing test cases.

2018-12-10 Thread Yarving Liu
For the:
self.assertEqual(self.item.category, 2)

this is because you defined self.item in setUp, and self.category = 1.


Others have no idea, expect answers the same.

On Tue, Dec 11, 2018 at 12:00 PM ANi  wrote:

> Hello,
> I am now trying to write test cases for my project, but I find some
> problems.
>
> 1.
>
>
> class FirstTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
>User.objects.create(username = 'johndoe', password =
> 'goodtobehere123')
>...
>
> def test_case_one(self):
>user = User.objects.get(pk=1)
># some assertions here
>
>...
>
> class SecondTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
> User.objects.create(username = 'janedoe', password =
> 'nicetobethere456')
>
> def test_case_one(self):
>user = User.objects.get(pk=1)
># some assertions here
>
>...
>
>
> If I run all the tests together, I can pass the FirstTest while getting
> error of "django.contrib.auth.models.DoesNotExist: User matching query does
> not exist." on the SecondTest.
> If I run two test cases separately, all tests are passed.
> Then solved it by changing it into this:
>
>
> class FirstTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
> cls.user = User.objects.create(username = 'johndoe', password =
> 'goodtobehere123')
> ...
>
> def test_case_one(self):
>self.assertEqual(self.user.somefunc(), something)
># some assertions here
>
>...
>
> class SecondTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
>cls.user = User.objects.create(username = 'janedoe', password =
> 'nicetobethere456')
>...
>
> def test_case_one(self):
>self.assertEqual(self.user.somefunc(), something)
># some assertions here
>
>...
>
>
>
> However I don't know why.?
>
>
> 2.
>
> class ViewTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
> cls.user = User.objects.create(username = 'johndoe', password =
> 'goodtobehere123')
> ...
>
>  def setUp(self):
>  self.item = Item.objects.create(
>  category = 1,
>  item_content = 'content content',
>  )
>
>
>  def test_item_update(self):
>  # the view will update the item and return HTTP status code 200.
>  # if the item is not exist, raise Http404
>  self.c = Client()
>  resp = self.c.post(
> reverse('update_item', kwargs={"pk":self.item.pk}),
> data = {
> "category": 2,
> "content": "item content",
>  }
>  )
>
>  self.assertEqual(resp.status_code, 200)
>  self.assertEqual(self.item.category, 2)
>
>  def test_item_delete(self):
>  # the view will delete the item and return HTTP status code 200.
>  # if the item is not exist, raise Http404
>  self.c = Client()
>  resp = self.c.post(
> reverse('delete_item'),
> data = {
> "pk": self.item.pk
>  }
>  )
>
>  self.assertEqual(resp.status_code, 200)
>
>
>
>
> I got " AssertionError: 1 != 2 ". for test_item_update()
> and "AssertionError: 404 != 200". for test_item_delete()
>
> I think it is reasonable but obviously I misunderstand something.
>
> Thank you. I will be very happy if you want to help me >___<
>
>
>
> --
> 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/f1f9855a-3461-45a1-bdee-2ec901a7f718%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/CAMNWVFq4%3DG8RVZESc5Nvq7agPvwnGYbdfz8aF3Q3rvXvHGMZkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems from writing test cases.

2018-12-10 Thread ANi
Oh. ok :)

Then I tried to call again the item object by its pk, and it works.
item = Item.objects.get(pk=self.item.pk)

and sorry for the test_item_delete(). 
I passed the wrong parameter so the view got a None to retrieve the item 
object, that's why it returns 404.
 

thank you so much.

-- 
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/18e1efaa-a625-4c66-b669-f99cdb04fe0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.