Re: Attribute error, with a very basic banking app

2016-08-26 Thread Neil Hunt
Thanks for that Michal, I see what you mean. I've bookmarked it. Thanks to
everyone for all the detailed replies it really helps make sense of CBV :)

On Fri, Aug 26, 2016 at 3:48 PM, Michal Petrucha <
michal.petru...@konk.org> wrote:

> On Fri, Aug 26, 2016 at 10:29:16AM -0400, Andromeda Yelton wrote:
> > In my experience, CBVs are useful when the view you want to write is
> > basically a create, read, update, or delete operation on a single
> database
> > item, or a bunch of instances of the same model (...and it turns out a
> lot
> > of web app pages are just that). And they're useful because they let you
> do
> > that with almost no lines of code - they take care of all the things
> you'd
> > have to write over and over, and let you focus on the things that are
> > unique to your use case.
> >
> > The farther away your business logic is from that, the more you need to
> > understand the actual methods available and the inheritance tree and so
> > forth. It took me a while to get over this hurdle too, but now that I
> have
> > I use CBVs exclusively.
>
> I'll just chime in with a reference to http://ccbv.co.uk/, which is an
> invaluable resource whenever you're doing anything with CBVs that
> involves more than setting the ``template_name`` and ``model``
> attributes. In my opinion, CCBV makes a lot of the pain involved in
> dealing with CBVs go away.
>
> Cheers,
>
> Michal
>
> --
> 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/vXAou_bCuhE/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/20160826144853.GA6601%40konk.org.
> 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/CACaWuFT1cL7jmsUbmj3g%3Dskp9HK5VtunWxSx8i9M8%2BAqOF2yzg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Attribute error, with a very basic banking app

2016-08-26 Thread Neil Hunt
I've read the tutorial but I didn't fully appreciate how useful CBV are.
Amazing as well that sometimes you can write almost no code. Thanks a lot
for explaining that.

On Fri, Aug 26, 2016 at 3:29 PM, Andromeda Yelton <
andromeda.yel...@gmail.com> wrote:

> In my experience, CBVs are useful when the view you want to write is
> basically a create, read, update, or delete operation on a single database
> item, or a bunch of instances of the same model (...and it turns out a lot
> of web app pages are just that). And they're useful because they let you do
> that with almost no lines of code - they take care of all the things you'd
> have to write over and over, and let you focus on the things that are
> unique to your use case.
>
> The farther away your business logic is from that, the more you need to
> understand the actual methods available and the inheritance tree and so
> forth. It took me a while to get over this hurdle too, but now that I have
> I use CBVs exclusively.
>
> On Fri, Aug 26, 2016 at 10:13 AM, Neil Hunt <hunt.n...@gmail.com> wrote:
>
>> heh heh. I don't fully appreciate the usefulness of CBV at the moment.
>> Getting a simple example working helps as much as reading the tutorial.
>> Thanks again for your help,
>>
>> Neil
>>
>> On Fri, Aug 26, 2016 at 2:24 PM, Sergiy Khohlov <skhoh...@gmail.com>
>> wrote:
>>
>>> Never mind.
>>>  Few year ago I  was thinking that moving to CBV is bad idea, but
>>> suddenly  BUUUHHH !! in my head and everything was clear.
>>>
>>> Many thanks,
>>>
>>> Serge
>>>
>>>
>>> +380 636150445
>>> skype: skhohlov
>>>
>>> On Fri, Aug 26, 2016 at 3:40 PM, Neil Hunt <hunt.n...@gmail.com> wrote:
>>>
>>>> Hello Serge,
>>>>
>>>> I can't believe that's all I have to add to get the class based views
>>>> to work. It seems easier to get it to work than I thought it would be. Now
>>>> that you've explained it. Thank you so much for that.
>>>>
>>>> Kind regards,
>>>>
>>>> Neil
>>>>
>>>> On Fri, Aug 26, 2016 at 11:46 AM, Sergiy Khohlov <skhoh...@gmail.com>
>>>> wrote:
>>>>
>>>>>  Hello Neil,
>>>>>
>>>>>  It is nota problem  to use Class based view. Could you please  update
>>>>> your views.py  with next code.
>>>>>  Look like you would like to have detail  of the deposit in this case
>>>>> add next string to the header
>>>>>
>>>>> from  django.views.generic import DetailView
>>>>> from models import Account1, Person
>>>>>
>>>>>
>>>>>  # next  you should create a special view class for each Account1
>>>>>
>>>>>
>>>>>  class Deposit(DetailView):
>>>>> model = Account1
>>>>>
>>>>>
>>>>>   Of course  function Deposit is  useless
>>>>>
>>>>>  thats all.
>>>>>
>>>>>
>>>>>  P.S. Look like better way is adding auth  and receive person using
>>>>> auth data. In this case  every authorized person can  connect to his
>>>>> account  using auth info and  account id
>>>>>
>>>>> Many thanks,
>>>>>
>>>>> Serge
>>>>>
>>>>>
>>>>> +380 636150445
>>>>> skype: skhohlov
>>>>>
>>>>> On Thu, Aug 25, 2016 at 8:27 PM, Neil Hunt <hunt.n...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Thank you so much Andromeda. I didn't know you could use class based
>>>>>> views. I'll have a look at the documents. I don't know why I was trying 
>>>>>> to
>>>>>> use them when I didn't need to.
>>>>>>
>>>>>> On Thu, Aug 25, 2016 at 4:23 PM, Andromeda Yelton <
>>>>>> andromeda.yel...@gmail.com> wrote:
>>>>>>
>>>>>>> The stacktrace is helpful, thanks!
>>>>>>>
>>>>>>> The specific message with the AttributeError is helpful here:
>>>>>>> `AttributeError: 'module' object has no attribute 'DepositView'`
>>>>>>>
>>>>>>> The line above it is `  File 
>>>>>>> "/home/soupdragon/DJapps/banking/mybank/banking/urls.py",
>>>>>>> 

Re: Attribute error, with a very basic banking app

2016-08-26 Thread Neil Hunt
heh heh. I don't fully appreciate the usefulness of CBV at the moment.
Getting a simple example working helps as much as reading the tutorial.
Thanks again for your help,

Neil

On Fri, Aug 26, 2016 at 2:24 PM, Sergiy Khohlov <skhoh...@gmail.com> wrote:

> Never mind.
>  Few year ago I  was thinking that moving to CBV is bad idea, but suddenly
>  BUUUHHH !! in my head and everything was clear.
>
> Many thanks,
>
> Serge
>
>
> +380 636150445
> skype: skhohlov
>
> On Fri, Aug 26, 2016 at 3:40 PM, Neil Hunt <hunt.n...@gmail.com> wrote:
>
>> Hello Serge,
>>
>> I can't believe that's all I have to add to get the class based views to
>> work. It seems easier to get it to work than I thought it would be. Now
>> that you've explained it. Thank you so much for that.
>>
>> Kind regards,
>>
>> Neil
>>
>> On Fri, Aug 26, 2016 at 11:46 AM, Sergiy Khohlov <skhoh...@gmail.com>
>> wrote:
>>
>>>  Hello Neil,
>>>
>>>  It is nota problem  to use Class based view. Could you please  update
>>> your views.py  with next code.
>>>  Look like you would like to have detail  of the deposit in this case
>>> add next string to the header
>>>
>>> from  django.views.generic import DetailView
>>> from models import Account1, Person
>>>
>>>
>>>  # next  you should create a special view class for each Account1
>>>
>>>
>>>  class Deposit(DetailView):
>>> model = Account1
>>>
>>>
>>>   Of course  function Deposit is  useless
>>>
>>>  thats all.
>>>
>>>
>>>  P.S. Look like better way is adding auth  and receive person using auth
>>> data. In this case  every authorized person can  connect to his account
>>>  using auth info and  account id
>>>
>>> Many thanks,
>>>
>>> Serge
>>>
>>>
>>> +380 636150445
>>> skype: skhohlov
>>>
>>> On Thu, Aug 25, 2016 at 8:27 PM, Neil Hunt <hunt.n...@gmail.com> wrote:
>>>
>>>> Thank you so much Andromeda. I didn't know you could use class based
>>>> views. I'll have a look at the documents. I don't know why I was trying to
>>>> use them when I didn't need to.
>>>>
>>>> On Thu, Aug 25, 2016 at 4:23 PM, Andromeda Yelton <
>>>> andromeda.yel...@gmail.com> wrote:
>>>>
>>>>> The stacktrace is helpful, thanks!
>>>>>
>>>>> The specific message with the AttributeError is helpful here:
>>>>> `AttributeError: 'module' object has no attribute 'DepositView'`
>>>>>
>>>>> The line above it is `  File 
>>>>> "/home/soupdragon/DJapps/banking/mybank/banking/urls.py",
>>>>> line 8, in 
>>>>> url(r'^deposit/$', views.DepositView.as_view(), name='deposit'),`
>>>>>
>>>>> So I checked to see if your views.py contains anything named
>>>>> DepositView...and it does not. That's why the AttributeError is showing 
>>>>> up.
>>>>>
>>>>> The `DepositView.as_view()` syntax is suitable for class-based views,
>>>>> which means I expect to see something in your views.py to the effect of:
>>>>>
>>>>> class DepositView(View):
>>>>>   def post(self, request, *args, **kwargs):
>>>>> // the logic in your deposit() function actually belongs here
>>>>>
>>>>> Have a look at the class-based views documentation to see what the
>>>>> different classes are, and what options they provide you.
>>>>>
>>>>> Alternately, your urls.py could reference views.deposit (which does
>>>>> exist) instead of views.DepositView (which does not).
>>>>>
>>>>> Hope this helps!
>>>>>
>>>>> On Thu, Aug 25, 2016 at 11:14 AM, Neil Hunt <hunt.n...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Thanks for your speedy reply, I've attached the stack trace
>>>>>>
>>>>>> On Thursday, August 25, 2016 at 4:00:16 PM UTC+1, ludovic coues wrote:
>>>>>>>
>>>>>>> Could you share the full stack trace you get when trying to run the
>>>>>>> server ?
>>>>>>> The attribute error should come with a ton of information like the
>>>>>>> file and the line where the error occur.
>>>>>&g

Re: Attribute error, with a very basic banking app

2016-08-26 Thread Neil Hunt
Hello Serge,

I can't believe that's all I have to add to get the class based views to
work. It seems easier to get it to work than I thought it would be. Now
that you've explained it. Thank you so much for that.

Kind regards,

Neil

On Fri, Aug 26, 2016 at 11:46 AM, Sergiy Khohlov <skhoh...@gmail.com> wrote:

>  Hello Neil,
>
>  It is nota problem  to use Class based view. Could you please  update
> your views.py  with next code.
>  Look like you would like to have detail  of the deposit in this case add
> next string to the header
>
> from  django.views.generic import DetailView
> from models import Account1, Person
>
>
>  # next  you should create a special view class for each Account1
>
>
>  class Deposit(DetailView):
> model = Account1
>
>
>   Of course  function Deposit is  useless
>
>  thats all.
>
>
>  P.S. Look like better way is adding auth  and receive person using auth
> data. In this case  every authorized person can  connect to his account
>  using auth info and  account id
>
> Many thanks,
>
> Serge
>
>
> +380 636150445
> skype: skhohlov
>
> On Thu, Aug 25, 2016 at 8:27 PM, Neil Hunt <hunt.n...@gmail.com> wrote:
>
>> Thank you so much Andromeda. I didn't know you could use class based
>> views. I'll have a look at the documents. I don't know why I was trying to
>> use them when I didn't need to.
>>
>> On Thu, Aug 25, 2016 at 4:23 PM, Andromeda Yelton <
>> andromeda.yel...@gmail.com> wrote:
>>
>>> The stacktrace is helpful, thanks!
>>>
>>> The specific message with the AttributeError is helpful here:
>>> `AttributeError: 'module' object has no attribute 'DepositView'`
>>>
>>> The line above it is `  File 
>>> "/home/soupdragon/DJapps/banking/mybank/banking/urls.py",
>>> line 8, in 
>>> url(r'^deposit/$', views.DepositView.as_view(), name='deposit'),`
>>>
>>> So I checked to see if your views.py contains anything named
>>> DepositView...and it does not. That's why the AttributeError is showing up.
>>>
>>> The `DepositView.as_view()` syntax is suitable for class-based views,
>>> which means I expect to see something in your views.py to the effect of:
>>>
>>> class DepositView(View):
>>>   def post(self, request, *args, **kwargs):
>>> // the logic in your deposit() function actually belongs here
>>>
>>> Have a look at the class-based views documentation to see what the
>>> different classes are, and what options they provide you.
>>>
>>> Alternately, your urls.py could reference views.deposit (which does
>>> exist) instead of views.DepositView (which does not).
>>>
>>> Hope this helps!
>>>
>>> On Thu, Aug 25, 2016 at 11:14 AM, Neil Hunt <hunt.n...@gmail.com> wrote:
>>>
>>>> Thanks for your speedy reply, I've attached the stack trace
>>>>
>>>> On Thursday, August 25, 2016 at 4:00:16 PM UTC+1, ludovic coues wrote:
>>>>>
>>>>> Could you share the full stack trace you get when trying to run the
>>>>> server ?
>>>>> The attribute error should come with a ton of information like the
>>>>> file and the line where the error occur.
>>>>>
>>>>> 2016-08-25 16:57 GMT+02:00 Neil Hunt <hunt...@gmail.com>:
>>>>> > I've beem working on a simple banking app based on the Django
>>>>> tutorial.
>>>>> > Thanks to your help it almost works now. It was working using
>>>>> templates but
>>>>> > after making some changes to get HttpResponseRedirect to work I
>>>>> changed what
>>>>> > was in the urls file like it shows in the tutorial. Now, the server
>>>>> doesn't
>>>>> > run. It says there's an attribute error. I've temporarily left the
>>>>> user name
>>>>> > and password in at the moment. I had a look at their tutorial how to
>>>>> do a
>>>>> > use the Django authentication system (thanks for telling me about
>>>>> that) and
>>>>> > I'm going to change that after I understand what's going on here.
>>>>> It's
>>>>> > amazing how much you can do with Django. Do you think with time you
>>>>> get more
>>>>> > used to what different errors mean? The errors seem new and
>>>>> confusing to me
>>>>> > at the moment. Any help would be very much appreciated. Thanks in
>&g

Re: Attribute error, with a very basic banking app

2016-08-25 Thread Neil Hunt
Thank you so much Andromeda. I didn't know you could use class based views.
I'll have a look at the documents. I don't know why I was trying to use
them when I didn't need to.

On Thu, Aug 25, 2016 at 4:23 PM, Andromeda Yelton <
andromeda.yel...@gmail.com> wrote:

> The stacktrace is helpful, thanks!
>
> The specific message with the AttributeError is helpful here:
> `AttributeError: 'module' object has no attribute 'DepositView'`
>
> The line above it is `  File "/home/soupdragon/DJapps/
> banking/mybank/banking/urls.py", line 8, in 
> url(r'^deposit/$', views.DepositView.as_view(), name='deposit'),`
>
> So I checked to see if your views.py contains anything named
> DepositView...and it does not. That's why the AttributeError is showing up.
>
> The `DepositView.as_view()` syntax is suitable for class-based views,
> which means I expect to see something in your views.py to the effect of:
>
> class DepositView(View):
>   def post(self, request, *args, **kwargs):
> // the logic in your deposit() function actually belongs here
>
> Have a look at the class-based views documentation to see what the
> different classes are, and what options they provide you.
>
> Alternately, your urls.py could reference views.deposit (which does exist)
> instead of views.DepositView (which does not).
>
> Hope this helps!
>
> On Thu, Aug 25, 2016 at 11:14 AM, Neil Hunt <hunt.n...@gmail.com> wrote:
>
>> Thanks for your speedy reply, I've attached the stack trace
>>
>> On Thursday, August 25, 2016 at 4:00:16 PM UTC+1, ludovic coues wrote:
>>>
>>> Could you share the full stack trace you get when trying to run the
>>> server ?
>>> The attribute error should come with a ton of information like the
>>> file and the line where the error occur.
>>>
>>> 2016-08-25 16:57 GMT+02:00 Neil Hunt <hunt...@gmail.com>:
>>> > I've beem working on a simple banking app based on the Django
>>> tutorial.
>>> > Thanks to your help it almost works now. It was working using
>>> templates but
>>> > after making some changes to get HttpResponseRedirect to work I
>>> changed what
>>> > was in the urls file like it shows in the tutorial. Now, the server
>>> doesn't
>>> > run. It says there's an attribute error. I've temporarily left the
>>> user name
>>> > and password in at the moment. I had a look at their tutorial how to
>>> do a
>>> > use the Django authentication system (thanks for telling me about
>>> that) and
>>> > I'm going to change that after I understand what's going on here. It's
>>> > amazing how much you can do with Django. Do you think with time you
>>> get more
>>> > used to what different errors mean? The errors seem new and confusing
>>> to me
>>> > at the moment. Any help would be very much appreciated. Thanks in
>>> advnace.
>>> >
>>> > --
>>> > 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/b30091ce-fcbf
>>> -461e-869e-bba72eb9dcfe%40googlegroups.com.
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>>
>>> --
>>>
>>> Cordialement, Coues Ludovic
>>> +336 148 743 42
>>>
>> --
>> 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/ms
>> gid/django-users/b9b247a9-830d-4cc0-a441-5a8013899f13%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/b9b247a9-830d-4cc0-a441-5a8013899f13%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Andr

Re: Attribute error, with a very basic banking app

2016-08-25 Thread Neil Hunt
Thanks for your speedy reply, I've attached the stack trace

On Thursday, August 25, 2016 at 4:00:16 PM UTC+1, ludovic coues wrote:
>
> Could you share the full stack trace you get when trying to run the server 
> ? 
> The attribute error should come with a ton of information like the 
> file and the line where the error occur. 
>
> 2016-08-25 16:57 GMT+02:00 Neil Hunt <hunt...@gmail.com >: 
> > I've beem working on a simple banking app based on the Django tutorial. 
> > Thanks to your help it almost works now. It was working using templates 
> but 
> > after making some changes to get HttpResponseRedirect to work I changed 
> what 
> > was in the urls file like it shows in the tutorial. Now, the server 
> doesn't 
> > run. It says there's an attribute error. I've temporarily left the user 
> name 
> > and password in at the moment. I had a look at their tutorial how to do 
> a 
> > use the Django authentication system (thanks for telling me about that) 
> and 
> > I'm going to change that after I understand what's going on here. It's 
> > amazing how much you can do with Django. Do you think with time you get 
> more 
> > used to what different errors mean? The errors seem new and confusing to 
> me 
> > at the moment. Any help would be very much appreciated. Thanks in 
> advnace. 
> > 
> > -- 
> > 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/b30091ce-fcbf-461e-869e-bba72eb9dcfe%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
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/b9b247a9-830d-4cc0-a441-5a8013899f13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


tracext
Description: Binary data


Attribute error, with a very basic banking app

2016-08-25 Thread Neil Hunt
I've beem working on a simple banking app based on the Django tutorial. 
Thanks to your help it almost works now. It was working using templates but 
after making some changes to get HttpResponseRedirect to work I changed 
what was in the urls file like it shows in the tutorial. Now, the server 
doesn't run. It says there's an attribute error. I've temporarily left the 
user name and password in at the moment. I had a look at their tutorial how 
to do a use the Django authentication system (thanks for telling me about 
that) and I'm going to change that after I understand what's going on here. 
It's amazing how much you can do with Django. Do you think with time you 
get more used to what different errors mean? The errors seem new and 
confusing to me at the moment. Any help would be very much appreciated. 
Thanks in advnace.

-- 
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/b30091ce-fcbf-461e-869e-bba72eb9dcfe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Title: Login
{% load staticfiles %}


 
 





{% csrf_token %}
Your details:

Username:

Password:







from django.shortcuts import get_object_or_404
from django.shortcuts import render
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
#from django.template import loader
from django.views import generic

from .models import Person, Account1

# Create your views here.
def deposit(request):
	selected_rbox = request.POST.get('Account1')
	selected_rbox = request.POST.get('Account2')
	selected_amount = request.POST.get('Amount')
	person = Person
	account1 = Account1
	context = {'account1':account1,'person':person}
	template = loader.get_template('banking/deposit.html')
	return HttpResponse(template.render(context,request))

def hello(request):
	person = Person
	account1 = Account1
	context = {'account1':account1,'person':person}
	#template = loader.get_template('banking/login.html')
	#return HttpResponse(template.render(context,request))
	return render(request, 'banking/login.html')
	#return render(request, 'banking/login.html', {
	#	'person': person,
	#	'error_message': "You didn't select a choice.",
#	})
	
def login(request):
	#account1 = get_object_or_404(Account1) 
	#person = get_object_or_404(Person) 
	account1 = Account1
	person = Person 
	try:
		selected_login = request.POST.get('login')
		selected_username = request.POST.get('username')
		#selected_login = person.choice_set.get(pk=request.POST['login'])
		#selected_password = person.choice_set.get(pk=request.POST['password'])

	# What is Choice object doing in the line below?
	#except (KeyError, Choice.DoesNotExist):
	except (KeyError, Account1.DoesNotExist):
	#except (KeyError, Account1.DoesNotExist):
# Redisplay the question voting form.
		#account1 = get_object_or_404(Account1) 
		#person = get_object_or_404(Person) 
		#person = Person
		#account1 = Account1
		#return render(request, 'banking/login.html', {
	#'person': person,
	#'error_message': "You didn't select a choice.",
		#return render(request, 'banking/login.html')
		return render(request, 'banking/login.html', {
		'person': person,
		'error_message': "You didn't select a choice.",
	})

		#person = Person
		#account1 = Account1
		#context = {'account1':account1,'person':person}
		#template = loader.get_template('banking/login.html')
		#return HttpResponse(template.render(context,request)
	else:
	# Always return an HttpResponseRedirect after successfully dealing
	# with POST data. This prevents data from being posted twice if a
	# user hits the Back button.
		#person = Person
		#account1 = Account1
		#context = {'account1':account1,'person':person}
		#template = loader.get_template('banking/welcome.html')
		#return HttpResponse(template.render(context,request))
		return HttpResponseRedirect(reverse('banking:welcome'))


def transfer(request):
	person = Person
	account1 = Account1
	context = {'account1':account1,'person':person}
	template = loader.get_template('banking/transfer.html')
	return HttpResponse(template.render(context,request))

def welcome(request):
	person = Person
	account1 = Account1
	context = {'account1':account1,'person':person}
	template = loader.get_template('banking/welcome.html')
	return HttpResponse(template.render(context,request))

def withdraw(request):
	person = Person
	account1 = Account1
	context = {'account1':account1,'person':person}
	template = loader.get_template('banking/withdraw.html')
	return HttpResponse(template.render(context,request))
from 

Re: Testing an object

2016-08-01 Thread Neil Hunt
That was an silly basic python mistake. Doh! I just indented the method 
correctly and the test ran fine. Thanks a lot, ludovic :)

On Monday, August 1, 2016 at 12:58:01 PM UTC+1, ludovic coues wrote:
>
> Look like you forget to indent the method inside your class. 
>
> 2016-08-01 13:43 GMT+02:00 Neil Hunt <hunt...@gmail.com >: 
> > I've read and reread the tutorial and I'm working on writing a very 
> simple 
> > banking app by copying and modifying what's in the tutorial. I've 
> started a 
> > new project and copied what was on the first two pages of the tutorial 
> and 
> > I've written a new models file. Make migrations works okay with the new 
> > models. I tried testing these new models using the test below and the 
> > console came up with an attribute error. Did I make a stupid mistake 
> > somewhere? Any help would be much appreciated. 
> > 
> > Traceback (most recent call last): 
> >   File "/home/DJapps/banking/mybank/banking/test_models.py", line 12, in 
> > test_animals_can_speak 
> > self.assertEqual(person.get_first_name(), 'Bob') 
> > AttributeError: 'Person' object has no attribute 'get_first_name' 
> > 
> > 
> > from django.test import TestCase 
> > from banking.models import Person 
> > 
> > class PersonTestCase(TestCase): 
> > def setUp(self): 
> > Person.objects.create(first_name="Bob", last_name="Smith", 
> > login_name="myname", password="Dog") 
> > 
> > def test_animals_can_speak(self): 
> > """Animals that can speak are correctly identified""" 
> > person = Person.objects.get(first_name="Bob") 
> > #person = mommy.make(Person) 
> > self.assertEqual(person.get_first_name(), 'Bob') 
> > #self.assertEqual(person.get_last_name(), 'Smith') 
> > #self.assertEqual(person.get_login_name(), 'myname') 
> > #self.assertEqual(person.get_password(), 'Dog') 
> > #self.assertEqual(person._str__, person_text) 
> > 
> > New models... 
> > 
> > from django.db import models 
> > 
> > # Create your models here. 
> > class Person(models.Model): 
> > first_name = models.CharField(max_length=4,default="Bob") 
> > last_name = models.CharField(max_length=6,default="Smith") 
> > login_name = models.CharField(max_length=3,default="me") 
> > password = models.CharField(max_length=7, default="password") 
> > person_text = models.CharField(max_length=10, default="Bob Smith") 
> > 
> > def get_first_name(self): 
> > return self.first_name 
> > 
> > def get_last_name(self): 
> > return self.last_name 
> > 
> > def get_login_name(self): 
> > return self.login_name 
> > 
> > def get_password(self, user_input): 
> > return self.password 
> > 
> > def __str__(self): 
> > return self.person_text 
> > 
> > class Account1(models.Model): 
> > account_number = models.IntegerField(default=12345678) 
> > bank_balance = models.DecimalField(max_digits=4, decimal_places=2, 
> > default=12.99) 
> > interest_rate = models.IntegerField(default=2) 
> > account_text = models.CharField(max_length=16, default="Current 
> > Account") 
> > person = models.ForeignKey(Person, on_delete=models.CASCADE, 
> default="") 
> > 
> > 
> > def get_account_number(self): 
> > return self.account_number 
> > 
> > def get_bank_balance(self): 
> > return self.bank_balance 
> > 
> > def deposit(self, amount): 
> > self.bank_balance = self.bank_balance + amount 
> > return 
> > 
> > def get_interest_rate(self): 
> > return self.interest_rate 
> > 
> > def withdraw(self, amount): 
> > self.bank_balance = self.bank_balance - amount 
> > return 
> > 
> > def __str__(self): 
> > return self.account_text 
> > 
> > 
> > -- 
> > 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/1b946075-f532-408f-ace7-4e4361ad350b%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
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/1d80f305-6e5e-4cbc-8a9a-623dd730651e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Testing an object

2016-08-01 Thread Neil Hunt
I've read and reread the tutorial and I'm working on writing a very simple 
banking app by copying and modifying what's in the tutorial. I've started a 
new project and copied what was on the first two pages of the tutorial and 
I've written a new models file. Make migrations works okay with the new 
models. I tried testing these new models using the test below and the 
console came up with an attribute error. Did I make a stupid mistake 
somewhere? Any help would be much appreciated.

Traceback (most recent call last):
  File "/home/DJapps/banking/mybank/banking/test_models.py", line 12, in 
test_animals_can_speak
self.assertEqual(person.get_first_name(), 'Bob')
AttributeError: 'Person' object has no attribute 'get_first_name'


from django.test import TestCase
from banking.models import Person

class PersonTestCase(TestCase):
def setUp(self):
Person.objects.create(first_name="Bob", last_name="Smith", 
login_name="myname", password="Dog")

def test_animals_can_speak(self):
"""Animals that can speak are correctly identified"""
person = Person.objects.get(first_name="Bob")
#person = mommy.make(Person)
self.assertEqual(person.get_first_name(), 'Bob')
#self.assertEqual(person.get_last_name(), 'Smith')
#self.assertEqual(person.get_login_name(), 'myname')
#self.assertEqual(person.get_password(), 'Dog')
#self.assertEqual(person._str__, person_text)

New models...

from django.db import models

# Create your models here.
class Person(models.Model):
first_name = models.CharField(max_length=4,default="Bob")
last_name = models.CharField(max_length=6,default="Smith")
login_name = models.CharField(max_length=3,default="me")
password = models.CharField(max_length=7, default="password")
person_text = models.CharField(max_length=10, default="Bob Smith") 

def get_first_name(self):
return self.first_name

def get_last_name(self):
return self.last_name

def get_login_name(self):
return self.login_name

def get_password(self, user_input):
return self.password

def __str__(self):
return self.person_text

class Account1(models.Model):
account_number = models.IntegerField(default=12345678)
bank_balance = models.DecimalField(max_digits=4, decimal_places=2, 
default=12.99)
interest_rate = models.IntegerField(default=2)
account_text = models.CharField(max_length=16, default="Current 
Account")
person = models.ForeignKey(Person, on_delete=models.CASCADE, default="")


def get_account_number(self):
return self.account_number

def get_bank_balance(self):
return self.bank_balance

def deposit(self, amount):
self.bank_balance = self.bank_balance + amount
return

def get_interest_rate(self):
return self.interest_rate

def withdraw(self, amount):
self.bank_balance = self.bank_balance - amount
return

def __str__(self):
return self.account_text


-- 
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/1b946075-f532-408f-ace7-4e4361ad350b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Stuck on tutorial your first Django app part 2

2016-06-10 Thread Neil Hunt
I just went through the tutorial again to check what the definition of my 
__str__() method was and I noticed where the tutorial says to add a custom 
method to polls/models.py. Before I copied and pasted a whole new object 
and method to the file instead of adding the custom method to the object. 
The next bit works now, hurray. Sorry to ask such a stupid question. Thanks 
a lot for your speedy reply.

On Thursday, June 9, 2016 at 10:03:18 PM UTC+1, ke1g wrote:
>
> What is the definition of your __str__() method?
>
> On Thu, Jun 9, 2016 at 4:11 PM, Neil Hunt <hunt...@gmail.com 
> > wrote:
>
>> Hello,
>>
>> I'm enjoying the tutorial and now I'm stuck on the second page (writing 
>> your first Django app part 2), shortly after this paragraph.
>>
>> 'It’s important to add __str__() 
>> <https://docs.djangoproject.com/en/1.9/ref/models/instances/#django.db.models.Model.__str__>
>>  
>> methods to your models, not only for your own convenience when dealing with 
>> the interactive prompt, but also because objects’ representations are used 
>> throughout Django’s automatically-generated admin.'
>>
>> The tutorial says to go into the interactive shell again.
>>
>> This line runs without error.
>>
>> 'from polls.models import Question, Choice'
>>
>> The next line Question.objects.all() results in
>>
>> '[]' instead of 
>>
>> '[]'
>>
>> Any help would be much appreciated.
>>
>> -- 
>> 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/3154675a-5749-434e-9fce-3aae49014959%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/3154675a-5749-434e-9fce-3aae49014959%40googlegroups.com?utm_medium=email_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/6cfb84a1-8483-4d2b-bfbe-b90d990746e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Stuck on tutorial your first Django app part 2

2016-06-09 Thread Neil Hunt
Hello,

I'm enjoying the tutorial and now I'm stuck on the second page (writing 
your first Django app part 2), shortly after this paragraph.

'It’s important to add __str__() 

 
methods to your models, not only for your own convenience when dealing with 
the interactive prompt, but also because objects’ representations are used 
throughout Django’s automatically-generated admin.'

The tutorial says to go into the interactive shell again.

This line runs without error.

'from polls.models import Question, Choice'

The next line Question.objects.all() results in

'[]' instead of 

'[]'

Any help would be much appreciated.

-- 
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/3154675a-5749-434e-9fce-3aae49014959%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.