Re: Code vs Shell?

2018-07-23 Thread mottaz hejaze
python is not just web , python is very general and has many other usages ,
so you are developing but in a pythonic way , think of the shell as your
scratch paper ..

what if you want to learn a code snippet like querying the database with
filters , do you have to waste time build a complete app to learn that ?!

On Tue, 24 Jul 2018, 05:17 Mike Dewhirst,  wrote:

> On 24/07/2018 9:25 AM, roflcopterpaul wrote:
> > Hello, everyone!
> >
> > I am quite the scrub, having written a few super basic apps and
> > currently going through the Django tutorial. As I'm going through the
> > tutorial (creating a "polls" app), I've been perplexed by something
> > the whole time that I haven't been able to find an answer to -
> >
> > Why is much of the data the users see (i.e., the questions and answers
> > to the questions) written in the shell INSTEAD of simply being typed
> > up in the code/text editor? I'm new, so this is coming from a place of
> > ignorance, by why is that? It seems way more complicated and less
> > efficient.
>
> It is an education thing. Python is an interpreter which means it can
> interpret and execute code directly as well as read a script and execute
> from that.
>
> And you can enter data directly without needing to write/debug data
> entry code or skipping too far ahead of basic theory to get the Admin
> going.
>
> Typing stuff in and seeing the results demonstrates things actually
> working. If you believe, you don't need to do it.
>
> Typing it in directly gives you instant feedback and that's what a lot
> of people like. I've been using Python for a few years now and I still
> fire up the interpreter occasionally when I'm refreshing my memory about
> something I haven't used for a while. Or checking to prove something
> works as it should when results make me suspect I have gotten something
> wrong.
>
> YMMV
>
>
> >
> > Also, IS there a way to change up the code so everything can be
> > directly changed in the files themselves instead of in the shell?
> >
> > Thank you very much for any insight!
> > --
> > 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/00ef1cb4-3e87-4c3d-a5c6-8811408624de%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/django-users/00ef1cb4-3e87-4c3d-a5c6-8811408624de%40googlegroups.com?utm_medium=email&utm_source=footer
> >.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f6c0044d-b4f7-1638-90f4-b00eea84c855%40dewhirst.com.au
> .
> 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/CAHV4E-cNjct5YYuwpRW1jg81D9PNb%3DQ1a0OkMyxz9xgetwBDEQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to automatically fill out an auto increment number in form field?

2018-07-23 Thread mottaz hejaze
you can use count() in views or models to count number of objects then add
the new record

On Tue, 24 Jul 2018, 02:55 Alexander Joseph, 
wrote:

> Thanks Michael and Gerald. With an auto key field or primary key field
> would users still be able to input their own value? And if so how would I
> be able to give it a default attribute in a form that shows what the next
> number should be, if the user decides to choose to use the auto increment?
> Thanks again
>
> On Mon, Jul 23, 2018, 6:36 PM Gerald Brown  wrote:
>
>> From
>> "https://docs.djangoproject.com/en/2.0/topics/db/models/#automatic-primary-key-fields";
>> ,
>> it has a further definition of automatic primary key fields.  In your model
>> just add "(primary_key=True)"  to po_number field.
>>
>> On Tuesday, 24 July, 2018 07:54 AM, Michael MacIntosh wrote:
>>
>> Hi,
>>
>> Aren't you looking for the AutoField?
>>
>> https://docs.djangoproject.com/en/2.0/ref/models/fields/#autofield
>>
>> It will automatically increment based on each record added to the table.
>>
>>
>> As an aside, the problem you are having is that in python, the first
>> argument to a class is a reference to the instance of that class.  In C
>> this is often called a context.  In C++ and Java it would be like the
>> `this` pointer.  So you wouldn't generally pass "self" to a class member.
>>
>> Hope that helps!
>>
>> On 7/23/2018 1:39 PM, Alexander Joseph wrote:
>>
>> Hello,
>>
>> I have a model ...
>>
>> class PurchaseOrder(models.Model):
>> po_number = models.IntegerField(unique=True)
>>
>>
>> and a function ...
>>
>> def get_po_number(self, *args, **kwargs):
>> if not self.id:
>> last_po = PurchaseOrder.objects.order_by('po_number').last()
>> if last_po:
>> last_po_num = last_po.po_number[-2:]
>> new_po_num = int(last_po_num) + 1
>> else:
>> new_po_num = '0001'
>> self.po_number = new_po_num
>> return self.po_number
>>
>>
>> what I'm trying to do is use the get_po_number() function to get a
>> default value for the po_number field in the model. However when I set the
>> default in the model like so...
>>
>> class PurchaseOrder(models.Model):
>> po_number = models.IntegerField(unique=True,
>> default=get_po_number(self))
>>
>> it says "NameError: name 'self' is not defined"
>>
>>
>> What am I doing wrong? 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/6183c81e-54b8-4779-9bf3-c8c9e734f248%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> This message has been scanned for viruses and dangerous content by
>> *E.F.A. Project* , and is believed to be
>> clean.
>> Click here to report this message as spam.
>> 
>>
>>
>> --
>> 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/945d5f35-e98b-b1f1-a527-32ff83687668%40linear-systems.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> 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/wpq8f815GGE/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/a37859a4-3c35-6f19-6a9b-ef997361bcee%40gmail.com
>> 

Re: BEGIINER_ISSUE (FIRST DJANGO PROJECT): The install worked successfully! Congratulations! You are seeing this page because DEBUG=True is in your settings file and you have not configured any URLs.

2018-07-23 Thread mottaz hejaze
this is not an issue , please go to documentation and follow the tutorial

On Tue, 24 Jul 2018, 01:44 Vinko Sucur,  wrote:

> When i lounch my first djangoproject it always display the issue "The
> install worked successfully! Congratulations! You are seeing this page
> because DEBUG=True is in your settings file and you have not configured any
> URLs." (Look FIRTS DJANGO PROJECT.PGN)
>
> Please, how can I fix that problem, that is how to configure any URLs in
> my setting file.
>
> Thanks
>
> Vinko Sucur
>
> --
> 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/098a8104-7369-4fb5-a014-f9ca977d7079%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/CAHV4E-cjVX6cS94TkrDErc6t%2BkO2Vksvwo4wj9R6euXwoX5Zsg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Server complete html Static App without apache server and without modifying html code

2018-07-23 Thread mottaz hejaze
i dont understand .. why you need backend anyway ?

On Mon, 23 Jul 2018, 23:21 archit mehta,  wrote:

>
> Hi,
>
> I have oraclejet frontend application and want to server that using
> django, I did it with flask but don't know how to do with django.
>
> Here is complete description of my problem Please go through it and
> suggest some solution.
>
>
> https://stackoverflow.com/questions/51484839/how-to-serve-complete-htmlapp-with-django-server-using-views-py
>
>
>
>
> Regards,
> Archit
>
> --
> 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/231f5a83-c3cf-4a3e-87c2-ecc378b08b97%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/CAHV4E-fRtdo9Ae_%2BFFZeAS4B7PDDuznz4LjHjeT0pn2sQ%2BKwEQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How can i require the user to login to see the view ?

2018-07-23 Thread mottaz hejaze
The login_required decorator¶

login_required(*redirect_field_name='next'*, *login_url=None*)[source]


As a shortcut, you can use the convenient login_required()

decorator:

from django.contrib.auth.decorators import login_required
@login_requireddef my_view(request):
...


On Tue, 24 Jul 2018, 01:44 Mostafa Alaa,  wrote:

> the view of  app
>
> from django.shortcuts import render
> from .models import Article
> from django.contrib.auth.decorators import login_required
> # Create your views here.
> def index(request):
> articles = Article.objects.all()
> return  render(request,'app/index.html',{'articles':articles})
>
>
>
> def detail(request,slug):
> articles = Article.objects.get(slug=slug)
> return render(request, 'app/detail.html', {'articles':articles})
>
>
>
> @login_required
> def create_article(request):
> return render(request,'app/create.html')
>
>
>
>
>
>
> the settings of login
>
> LOGIN_REDIRECT_URL = '/app/index/'
> LOGIN_URL = '/accounts/login/?next=/'
>
>
>
> --
> 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/a169e289-8fa7-4bb2-971e-c75b4978474b%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/CAHV4E-dhSYB8BXF%3Dz8dExMF3SPqt9a4u3sy0j30ai19KQ7Z96Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with FilteredSelectMultiple

2018-07-23 Thread Ike
Hi Melvyn, 

Sorry for the late reply, also this is my first post here so I'm not really 
sure what's needed. FilteredSelectMultiple is a django admin widget so it 
isn't in the requirements.txt. 

I have managed to save to the database already via ajax request. However, I 
am unable to have the chosen items be shown the next time the user revisits 
the page. Appending options via jquery/javascript doesn't work. 

Attached are all the codes and 
requirements.txt: 
https://gist.github.com/Yggralith0/054f4bd1752a608ef3f96ce01bd8fe5c

Yours sincerely,
Ike

On Sunday, 22 July 2018 01:53:34 UTC+8, Melvyn Sopacua wrote:
>
> On zaterdag 21 juli 2018 14:38:11 CEST Ike wrote: 
> > Good day everyone, I've been stuck with a problem I am having and I 
> can't 
> > find any help online. 
>
> Even though you've done much effort to make a good problem description, 
> you're 
> still making us do a lot of work before we can diagnose your issue: 
>
> - imports are missing from code 
> - used modules (requirements.txt) are missing (where is 
> FilteredSelectWidget 
> from) 
> - get_success_url isn't properly indented 
> - the entire save code is missing (form_valid is not implemented) 
>
> It's much easier to either open source your project or setup an test 
> project 
> that actually works and has either a setup.py or requirements.txt, since 
> this 
> touches on several issues. 
>
> It's also completely unclear why you think you have to use function based 
> views. 
>
> If what you really want is to have a save done as soon as a name enters or 
> is 
> removed from the box on the right, then the scope just increased 
> tremendously 
> and you need to grow frontend skills. 
>
> Otherwise, things just work out of the box (upon form submission, you can 
> call 
> form.save() in Formview.is_valid()) or the widget isn't worth it's salt. 
> -- 
> 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/f429c818-dff1-45b5-8ab0-dc71726212f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Code vs Shell?

2018-07-23 Thread Mike Dewhirst

On 24/07/2018 9:25 AM, roflcopterpaul wrote:

Hello, everyone!

I am quite the scrub, having written a few super basic apps and 
currently going through the Django tutorial. As I'm going through the 
tutorial (creating a "polls" app), I've been perplexed by something 
the whole time that I haven't been able to find an answer to -


Why is much of the data the users see (i.e., the questions and answers 
to the questions) written in the shell INSTEAD of simply being typed 
up in the code/text editor? I'm new, so this is coming from a place of 
ignorance, by why is that? It seems way more complicated and less 
efficient.


It is an education thing. Python is an interpreter which means it can 
interpret and execute code directly as well as read a script and execute 
from that.


And you can enter data directly without needing to write/debug data 
entry code or skipping too far ahead of basic theory to get the Admin 
going.


Typing stuff in and seeing the results demonstrates things actually 
working. If you believe, you don't need to do it.


Typing it in directly gives you instant feedback and that's what a lot 
of people like. I've been using Python for a few years now and I still 
fire up the interpreter occasionally when I'm refreshing my memory about 
something I haven't used for a while. Or checking to prove something 
works as it should when results make me suspect I have gotten something 
wrong.


YMMV




Also, IS there a way to change up the code so everything can be 
directly changed in the files themselves instead of in the shell?


Thank you very much for any insight!
--
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/00ef1cb4-3e87-4c3d-a5c6-8811408624de%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/f6c0044d-b4f7-1638-90f4-b00eea84c855%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Prevent Django tests from accessing internet (except localhost)

2018-07-23 Thread Kum
Is there a way to prevent people from accidentally doing so?

On Monday, July 23, 2018 at 7:39:27 AM UTC-4, Jason wrote:
>
> you shouldn't be accessing external services with your tests, you should 
> mock or patch them with expected responses/failures and test based on that.
>

-- 
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/f883c2ee-defc-4480-a57e-c2c6534f236e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to automatically fill out an auto increment number in form field?

2018-07-23 Thread Alexander Joseph
Thanks Michael and Gerald. With an auto key field or primary key field
would users still be able to input their own value? And if so how would I
be able to give it a default attribute in a form that shows what the next
number should be, if the user decides to choose to use the auto increment?
Thanks again

On Mon, Jul 23, 2018, 6:36 PM Gerald Brown  wrote:

> From
> "https://docs.djangoproject.com/en/2.0/topics/db/models/#automatic-primary-key-fields";
> ,
> it has a further definition of automatic primary key fields.  In your model
> just add "(primary_key=True)"  to po_number field.
>
> On Tuesday, 24 July, 2018 07:54 AM, Michael MacIntosh wrote:
>
> Hi,
>
> Aren't you looking for the AutoField?
>
> https://docs.djangoproject.com/en/2.0/ref/models/fields/#autofield
>
> It will automatically increment based on each record added to the table.
>
>
> As an aside, the problem you are having is that in python, the first
> argument to a class is a reference to the instance of that class.  In C
> this is often called a context.  In C++ and Java it would be like the
> `this` pointer.  So you wouldn't generally pass "self" to a class member.
>
> Hope that helps!
>
> On 7/23/2018 1:39 PM, Alexander Joseph wrote:
>
> Hello,
>
> I have a model ...
>
> class PurchaseOrder(models.Model):
> po_number = models.IntegerField(unique=True)
>
>
> and a function ...
>
> def get_po_number(self, *args, **kwargs):
> if not self.id:
> last_po = PurchaseOrder.objects.order_by('po_number').last()
> if last_po:
> last_po_num = last_po.po_number[-2:]
> new_po_num = int(last_po_num) + 1
> else:
> new_po_num = '0001'
> self.po_number = new_po_num
> return self.po_number
>
>
> what I'm trying to do is use the get_po_number() function to get a default
> value for the po_number field in the model. However when I set the default
> in the model like so...
>
> class PurchaseOrder(models.Model):
> po_number = models.IntegerField(unique=True,
> default=get_po_number(self))
>
> it says "NameError: name 'self' is not defined"
>
>
> What am I doing wrong? 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/6183c81e-54b8-4779-9bf3-c8c9e734f248%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> This message has been scanned for viruses and dangerous content by
> *E.F.A. Project* , and is believed to be
> clean.
> Click here to report this message as spam.
> 
>
>
> --
> 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/945d5f35-e98b-b1f1-a527-32ff83687668%40linear-systems.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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/wpq8f815GGE/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/a37859a4-3c35-6f19-6a9b-ef997361bcee%40gmail.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 receivin

Re: How to automatically fill out an auto increment number in form field?

2018-07-23 Thread Gerald Brown
From 
"https://docs.djangoproject.com/en/2.0/topics/db/models/#automatic-primary-key-fields";, 
it has a further definition of automatic primary key fields.  In your 
model just add "(primary_key=True)" to po_number field.



On Tuesday, 24 July, 2018 07:54 AM, Michael MacIntosh wrote:


Hi,

Aren't you looking for the AutoField?

https://docs.djangoproject.com/en/2.0/ref/models/fields/#autofield

It will automatically increment based on each record added to the table.


As an aside, the problem you are having is that in python, the first 
argument to a class is a reference to the instance of that class.  In 
C this is often called a context.  In C++ and Java it would be like 
the `this` pointer.  So you wouldn't generally pass "self" to a class 
member.


Hope that helps!


On 7/23/2018 1:39 PM, Alexander Joseph wrote:

Hello,

I have a model ...

|
class PurchaseOrder(models.Model):
    po_number = models.IntegerField(unique=True)
|


and a function ...

|
def get_po_number(self, *args, **kwargs):
    if not self.id:
        last_po = PurchaseOrder.objects.order_by('po_number').last()
        if last_po:
            last_po_num = last_po.po_number[-2:]
            new_po_num = int(last_po_num) + 1
        else:
            new_po_num = '0001'
        self.po_number = new_po_num
        return self.po_number
|


what I'm trying to do is use the get_po_number() function to get a 
default value for the po_number field in the model. However when I 
set the default in the model like so...


|
class PurchaseOrder(models.Model):
    po_number = models.IntegerField(unique=True, 
default=get_po_number(self))

|

it says "NameError: name 'self' is not defined"


What am I doing wrong? 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/6183c81e-54b8-4779-9bf3-c8c9e734f248%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.

--
This message has been scanned for viruses and dangerous content by
*E.F.A. Project* , and is believed to be 
clean.
Click here to report this message as spam. 
 



--
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/945d5f35-e98b-b1f1-a527-32ff83687668%40linear-systems.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/a37859a4-3c35-6f19-6a9b-ef997361bcee%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to automatically fill out an auto increment number in form field?

2018-07-23 Thread Michael MacIntosh

Hi,

Aren't you looking for the AutoField?

https://docs.djangoproject.com/en/2.0/ref/models/fields/#autofield

It will automatically increment based on each record added to the table.


As an aside, the problem you are having is that in python, the first 
argument to a class is a reference to the instance of that class.  In C 
this is often called a context.  In C++ and Java it would be like the 
`this` pointer.  So you wouldn't generally pass "self" to a class member.


Hope that helps!


On 7/23/2018 1:39 PM, Alexander Joseph wrote:

Hello,

I have a model ...

|
class PurchaseOrder(models.Model):
    po_number = models.IntegerField(unique=True)
|


and a function ...

|
def get_po_number(self, *args, **kwargs):
    if not self.id:
        last_po = PurchaseOrder.objects.order_by('po_number').last()
        if last_po:
            last_po_num = last_po.po_number[-2:]
            new_po_num = int(last_po_num) + 1
        else:
            new_po_num = '0001'
        self.po_number = new_po_num
        return self.po_number
|


what I'm trying to do is use the get_po_number() function to get a 
default value for the po_number field in the model. However when I set 
the default in the model like so...


|
class PurchaseOrder(models.Model):
    po_number = models.IntegerField(unique=True, 
default=get_po_number(self))

|

it says "NameError: name 'self' is not defined"


What am I doing wrong? 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/6183c81e-54b8-4779-9bf3-c8c9e734f248%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.

--
This message has been scanned for viruses and dangerous content by
*E.F.A. Project* , and is believed to be 
clean.
Click here to report this message as spam. 
 



--
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/945d5f35-e98b-b1f1-a527-32ff83687668%40linear-systems.com.
For more options, visit https://groups.google.com/d/optout.


Connecting to remote host like Twitch to monitor chat using websockets

2018-07-23 Thread Dave Holly

Greetings,

Is it possible to use Django Channels and websockets to monitor the chat in 
twitch rooms, or other sites with chat rooms?  I would like to display 
extra graphics for users who send cheers of high amounts, like 1000, 2000, 
etc.  I have the display worked out in Django where I'm monitoring a simple 
local chat.  This would be used as an overlay web page for OBS for the 
broadcaster.  When someone posts a specific cheer amount, the javascript 
displays a message or gif on the overlay web page with a short timeout.  
It's basically to say Thank You to the tipper.

I haven't found any documentation or tutorials on using Django Channels for 
anything but setting up my own chat program.  

In the consumers, is there a way to connect to a site like twitch and 
search the DOM for specific chat messages, like cheers?  


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/79ddc763-57d5-4757-9026-f0960b06c5a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


BEGIINER_ISSUE (FIRST DJANGO PROJECT): The install worked successfully! Congratulations! You are seeing this page because DEBUG=True is in your settings file and you have not configured any URLs.

2018-07-23 Thread Vinko Sucur
When i lounch my first djangoproject it always display the issue "The 
install worked successfully! Congratulations! You are seeing this page 
because DEBUG=True is in your settings file and you have not configured any 
URLs." (Look FIRTS DJANGO PROJECT.PGN)

Please, how can I fix that problem, that is how to configure any URLs in my 
setting file.

Thanks

Vinko Sucur

-- 
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/098a8104-7369-4fb5-a014-f9ca977d7079%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How can i require the user to login to see the view ?

2018-07-23 Thread Mostafa Alaa
the view of  app 

from django.shortcuts import render
from .models import Article
from django.contrib.auth.decorators import login_required
# Create your views here.
def index(request):
articles = Article.objects.all()
return  render(request,'app/index.html',{'articles':articles})



def detail(request,slug):
articles = Article.objects.get(slug=slug)
return render(request, 'app/detail.html', {'articles':articles})



@login_required
def create_article(request):
return render(request,'app/create.html')






the settings of login

LOGIN_REDIRECT_URL = '/app/index/'
LOGIN_URL = '/accounts/login/?next=/'



-- 
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/a169e289-8fa7-4bb2-971e-c75b4978474b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Code vs Shell?

2018-07-23 Thread roflcopterpaul
Hello, everyone!

I am quite the scrub, having written a few super basic apps and currently 
going through the Django tutorial. As I'm going through the tutorial 
(creating a "polls" app), I've been perplexed by something the whole time 
that I haven't been able to find an answer to -

Why is much of the data the users see (i.e., the questions and answers to 
the questions) written in the shell INSTEAD of simply being typed up in the 
code/text editor? I'm new, so this is coming from a place of ignorance, by 
why is that? It seems way more complicated and less efficient.

Also, IS there a way to change up the code so everything can be directly 
changed in the files themselves instead of in the shell?

Thank you very much for any insight!

-- 
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/00ef1cb4-3e87-4c3d-a5c6-8811408624de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Server complete html Static App without apache server and without modifying html code

2018-07-23 Thread archit mehta

Hi,

I have oraclejet frontend application and want to server that using django, 
I did it with flask but don't know how to do with django.

Here is complete description of my problem Please go through it and suggest 
some solution.

https://stackoverflow.com/questions/51484839/how-to-serve-complete-htmlapp-with-django-server-using-views-py




Regards,
Archit

-- 
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/231f5a83-c3cf-4a3e-87c2-ecc378b08b97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to automatically fill out an auto increment number in form field?

2018-07-23 Thread Alexander Joseph
Hello,

I have a model ...

class PurchaseOrder(models.Model):
po_number = models.IntegerField(unique=True)


and a function ...

def get_po_number(self, *args, **kwargs):
if not self.id:
last_po = PurchaseOrder.objects.order_by('po_number').last()
if last_po:
last_po_num = last_po.po_number[-2:]
new_po_num = int(last_po_num) + 1
else:
new_po_num = '0001'
self.po_number = new_po_num
return self.po_number


what I'm trying to do is use the get_po_number() function to get a default 
value for the po_number field in the model. However when I set the default 
in the model like so... 

class PurchaseOrder(models.Model):
po_number = models.IntegerField(unique=True, 
default=get_po_number(self))

it says "NameError: name 'self' is not defined"


What am I doing wrong? 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/6183c81e-54b8-4779-9bf3-c8c9e734f248%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Prevent Django tests from accessing internet (except localhost)

2018-07-23 Thread Melvyn Sopacua
On maandag 23 juli 2018 17:23:20 CEST chuck.horow...@packetviper.us wrote:
> Hi Kum,
> 
> I think Melvyn's suggestion is a good one.  Is there any reason you
> couldn't do:
> 
> 
> import DEBUG from yourapp.settings
> 
> 
> And then check against that for your testing?

Here's some code I used in a test:

class KvkApiTester(Testcase):
def skip_live_tests(self):
api_config = getattr(settings, 'KVKAPI', dict())
if not kvk_config or kvk_config['live_tests'] is False:
raise self.skipTest('live tests disabled or no KVKAPI 
configuration)

def test_api_key(self):
self.skip_live_tests()
... # actual tests

That way you know why tests are not running.

> 
> On Monday, July 23, 2018 at 8:22:17 AM UTC-4, Melvyn Sopacua wrote:
> > On maandag 23 juli 2018 13:39:27 CEST Jason wrote:
> > > you shouldn't be accessing external services with your tests
> > 
> > Non-sense. Part of interacting with a remote API is making sure it works
> > and
> > they didn't change anything (trust me, there's plenty of API's that change
> > without changing version numbers).
> > 
> > As for a global setting: no there isn't one. Your tests should have a
> > switch
> > of their own if you're worried about that.


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


Re: Prevent Django tests from accessing internet (except localhost)

2018-07-23 Thread chuck . horowitz
Hi Kum,

I think Melvyn's suggestion is a good one.  Is there any reason you 
couldn't do:
 

import DEBUG from yourapp.settings


And then check against that for your testing?

On Monday, July 23, 2018 at 8:22:17 AM UTC-4, Melvyn Sopacua wrote:
>
> On maandag 23 juli 2018 13:39:27 CEST Jason wrote: 
> > you shouldn't be accessing external services with your tests 
>
> Non-sense. Part of interacting with a remote API is making sure it works 
> and 
> they didn't change anything (trust me, there's plenty of API's that change 
> without changing version numbers). 
>
> As for a global setting: no there isn't one. Your tests should have a 
> switch 
> of their own if you're worried about that. 
>
> -- 
> 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/3634f858-d56a-4fa0-b946-398c344c64c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django admin panel records disappearing

2018-07-23 Thread dean raemaekers
Hello,

I am using the Django admin tool as an internal tool to reach into a remote 
database.

Most of my models work perfectly with the save. method additions I have 
added, but there are 2 that are not working.

What happens is that the admin screen gives a successful "save" message, 
but the grid view doesn't show any records.

When I click on the entry in the right hand "Recent changes" list, it says:

Change learner batch back to draft with ID "None" doesn't exist. Perhaps it 
was deleted?

Any advice on why this is happening would be welcome :)

Here is the model in question:

class ChangeLearnerBatchBackToDraft(models.Model):
ticket_number = models.CharField(max_length=10, default='')
provider_accreditation_num = models.CharField(max_length=30)
batch_id = models.CharField(max_length=30)
notes_log = models.TextField(default="No notes added", editable=False)

def save(self, *args, **kwargs): 
try:
commando_conn = psycopg2.connect(f"dbname='{DB}' user='{USER}' host='{HOST}' 
password='{PASS}'")
commando_cur = commando_conn.cursor()
commando_cur.execute(f"select * from res_partner where 
provider_accreditation_num='{self.provider_accreditation_num}';") 
res = commando_cur.fetchone()
real_provider_id = res[0]
self.notes_log = self.notes_log+f"\n{real_provider_id}\n"
except Exception as e:
raise AssertionError(e)

def __str__(self):
return str(self.provider_accreditation_num)+" - "+str(self.batch_id)

-- 
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/29e2a257-2631-4075-9453-8ce95b068f8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Prevent Django tests from accessing internet (except localhost)

2018-07-23 Thread Melvyn Sopacua
On maandag 23 juli 2018 13:39:27 CEST Jason wrote:
> you shouldn't be accessing external services with your tests

Non-sense. Part of interacting with a remote API is making sure it works and 
they didn't change anything (trust me, there's plenty of API's that change 
without changing version numbers).

As for a global setting: no there isn't one. Your tests should have a switch 
of their own if you're worried about that.

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


Re: Prevent Django tests from accessing internet (except localhost)

2018-07-23 Thread Jason
you shouldn't be accessing external services with your tests, you should 
mock or patch them with expected responses/failures and test based on that.

-- 
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/babc8253-b18b-4e98-b637-b2b4ddd749a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to fix "App 'polls' could not be found. Is it in INSTALLED_APPS?"

2018-07-23 Thread Gerald Brown
Don't use SUDO, just python manage.py makemigrations.  Also the "POLLS" 
is not necessary.



On Monday, 23 July, 2018 02:48 PM, Sitthiput Mongkolsri wrote:
Hi, i'm new to django. Just learn from the tutorial and found this 
problem. I don't know how to fix this, wish someone could. 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/df20c6f9-b742-42a2-bd12-493605606d66%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/3a2ff438-04e0-a444-01b4-0dbc309363e6%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Prevent Django tests from accessing internet (except localhost)

2018-07-23 Thread Kum
Hi,

Is there a global config I can enable to prevent any Django tests in a 
project from accessing the internet (i.e., only allow network calls to 
localhost) ?

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/fdec55c6-03eb-4ae8-8693-09187244c642%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to fix "App 'polls' could not be found. Is it in INSTALLED_APPS?"

2018-07-23 Thread Sitthiput Mongkolsri
Hi, i'm new to django. Just learn from the tutorial and found this problem. 
I don't know how to fix this, wish someone could. 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/df20c6f9-b742-42a2-bd12-493605606d66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.