Re: iterating over a queryset?

2013-09-21 Thread Johan Bergkvist
Daniel Roseman adviced me to use the Shell. This was a fantastic idea, and 
one I should have thought of myself! Anyway this helped me realize that I 
was referencing related models the wrong way. For some reason I thought 
that you should reference the model name and not the foreign key field 
name. It might just be me, but the documentation could seem a bit ambiguous 
on this point as all field names are lower case model names. 
Thanks for the help!

Den tirsdag den 17. september 2013 22.29.38 UTC+2 skrev Johan Bergkvist:
>
> Hi 
> I'm quite new to both django and python, and OOP for that matter. I do 
> have some embedded programming experience though.
> I have a question regarding querysets and dictionaries, I think.
>
> I was trying to build a model that provides an overview for subscribed 
> customers over their services and subscription status, etc.
>
> I have a model like this:
> class Customer (models.Model):
> user_id = models.AutoField( primary_key=True )
> auth_user = models.OneToOneField( User)
> subscription_type = models.ForeignKey( SubscType, related_name='type', 
> null = 'true', blank = 'true' )
> first_name = models.CharField( max_length = 64, verbose_name = 
> 'Fornavn' )
> last_name = models.CharField( max_length = 64, verbose_name = 
> 'Efternavn' )
> email_address = models.EmailField( max_length = 75, verbose_name = 
> 'eMail adresse' )
> join_date = models.DateField(auto_now_add = 'True', verbose_name = 
> 'Oprettet dato')
> delivery_address = models.ForeignKey( Address, 
> related_name='delivery', null = 'true', blank = 'true', verbose_name = 
> 'Leveringsadresse')
> address = models.ForeignKey( Address, related_name='home', 
> verbose_name = 'Hjemmeadresse' )
> phone_number = models.IntegerField(max_length = 10, verbose_name = 
> 'Telefon nummer')
> mobile_number = models.IntegerField(max_length = 10, blank = 'true', 
> null = 'true', verbose_name = 'Mobilnummer')
> image = models.ImageField(upload_to = 'Customer_img', blank = 'true', 
> verbose_name = 'Billede')
>
> class customerHistory (models.Model):
> customer_id = models.ForeignKey( Customer, related_name ='customer' )
> used_service = models.ManyToManyField(Services, 
> related_name='services' )
> action_date = models.DateField(auto_now_add = 'True')
> notes = models.TextField(verbose_name = 'Noter til handling')
>
> views like so:
> class CustomerInfo(TemplateView):
> #info page, displays base info about customer such as address, phone 
> number and  subscription entries
> template_name = "subscribtions/info.html"
>
> 
> def get_context_data(self, **kwargs):
> context = super(CustomerInfo, self).get_context_data(**kwargs)
> 
> context = Customer.objects.filter( auth_user = self.request.user 
> ).values(
> 'first_name', 
> 'last_name', 
> 'address', 
> 'delivery_address',
> 'phone_number',
> 'mobile_number',
> 'email_address', 
> 'join_date',
> 'subscription_type',
> 'image'
> ).get()
> return { 'info' : context }
>
> First of all, when I ommit the .get() method I cannot iterate over the 
> above query, I just get an empty queryset when doing this:
> {% for key, value in info.items %}
> {{ key }}: {{ value }} 
> {% empty %} 
>  no data 
> {% endfor %}
>
> I guess this has something to do with it not being a dictionary without 
> the .get() method. But in the documentation it seems that it should return 
> a iterable, I might be using it wrong, any suggestions?
>
> Second question is:
> When I try to to a "backwards relation" in the template, like so:
> {% for services in info.customerhistory_set.all %}
> {{ services }}
> {% endfor %}
> It also winds up empty.
> It might be that I'm interpreting the documentation wrong but I've been 
> googling on this subject and tried several different combinations. Any help?
>
> Thanks 
> Johan
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Testing in Django - newbie questions on first test failure and coverage

2013-09-21 Thread Derek
Rafael

I appreciate your reply; below I try and explain further the reasoning 
behind the approach I took.  If you can respond to that, it would help.


Firstly, the issue of test file locations - there are least two places I 
have found that recommend these be placed in a different directory:

>From http://toastdriven.com/blog/2011/apr/17/guide-to-testing-in-django-2/

"I prefer to split up the tests into a file structure that mirrors the 
app's setup. To do this, we create a new tests directory then move the 
existing tests.py into tests/views.py."

From 
https://pycon-2012-notes.readthedocs.org/en/latest/testing_and_django.html

"Don’t make the mistake of putting the tests for your app in a tests.py, 
because then other people who use your app will be forced to run your tests 
when they don’t really need to. Better to put your tests in another 
directory."

So this approach should be OK; and the tests seem work - but with that 
strange error message.  Still not sure what the exact cause is...


Thanks for the factory_boy suggestion.  I had looked at it, but was trying 
to avoid having to learn too may things all at once!  The code I have used 
for loading my fixtures comes from 
http://stackoverflow.com/questions/979434/how-to-load-fixtures-only-once-in-django-unit-tests
  
- and I added that because of the exact problem raised in that question; 
that Django reloads the fixtures for every single test; and that just seems 
to slow things right down (we have a lot of fixtures we need for our 
database).  if you can suggest another or better way to load our fixtures 
just once for a whole class of tests, I'd appreciate hearing about that.

Thanks
Derek


On Monday, 16 September 2013 23:20:41 UTC+2, Rafael Durán Castañeda wrote:
>
> Hi,
>
> Some answers inline and links at the end:
>
> 2013/9/15 Derek >
>
>> I have an existing Django (1.4) project, with multiple apps and extensive 
>> business logic, that I need to write tests for.  Based on a day or two of 
>> reading of the core Django docs and numerous blogs (each of which go about 
>> things subtly differently!?), I have made a start.  As part of the seeming 
>> "best practice" setup, I have also installed django-nose and coverage.
>>
>> Currently, I have problems with my first test not working and also with 
>> coverage seemingly not finding my test. 
>>  
>> I have a separate `tests` directory in my project, with sub-directories; 
>> each corresponding to an app.  Each sub-directory then has a models, views, 
>> and functions Python files; acting as placeholders for the test code I 
>> think need to write.  In the root of the `tests` directory, I have an 
>> __init__.py file that has a number of lines that look like `from 
>> myproj.app1.functions import *`.
>>
>  
> Most Django apps. place tests into the app. directory tests 
> module/package, so I think your layout may cause some Django test runner 
> may not able to find your tests. 
>
>
>> I have changed the settings.py file to look like this (so that the tests 
>> use a "fast" sqlite database):
>>
>> if 'test' in sys.argv:
>> DATABASES = {
>> 'default': {
>> 'ENGINE': 'django.db.backends.sqlite3',
>> 'NAME': 'test_db'
>> }
>> }
>> else:
>> DATABASES = {
>> 'default': {
>> 'ENGINE': 'django.db.backends.mysql',
>> # etc ... normal setup
>>
>>
>> The first test, in the first functions.py file, looks like this:
>>
>>
>> from django.test import TestCase
>> from django.core import management
>> from app1.models import default_Property  # function to be tested
>>
>> def setup():
>> management.call_command('loaddata', 
>> 'app1/fixtures/initial_data.json', verbosity=1)
>>
>> def teardown():
>> management.call_command('flush', verbosity=1, interactive=False)
>>
>> class FunctionsTestCase(TestCase):
>>
>> def _fixture_setup(self):
>> pass
>>
>> def test_default_Property(self):
>> self.assertEqual(default_Property(), None)
>>
>>
>>
> Don' t do this! Django provides enough functionality for managing fixtures 
> with ease(see [1]), you don´t need to write custom fixture handling. Even 
> in the case you need more than Django fixtures provides, there are some 
> thirty packages you probably want to look before even thinking about write 
> your own code (I really like factory_boy [2]
> ).
>  
>
>> The default_Property() function in app1 is just set to `return None` for 
>> now, so that the above test should work.
>>
>> However, the test fails.  I get this strange error:
>>
>> ==
>> ERROR: test_default_Property (myproj.app1.tests.FunctionsTestCase)
>> --
>> Traceback (most recent call last):
>>   File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", 
>> line 508, in __call__
>> self._post_teardown()
>>   File "/usr/local/lib/python2.7/dist-pa

Re: and keyword arguments '{u'student_id': None, u'school_id': 1}' not found.

2013-09-21 Thread Daniel Roseman
On Saturday, 21 September 2013 04:44:33 UTC+1, Trung Nguyen wrote:

> Django Version:1.5.2Exception Type:NoReverseMatchException Value:
>
> Reverse for 'gradingstudent' with arguments '()' and keyword arguments 
> '{u'student_id': None, u'school_id': 1}' not found.
>
> Exception 
> Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py
>  
> in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4
>  I am new to Django. I got this error and struggle to find a solution for 
> it but no luck. Please help!
>
> View.py   def grading_student(request, school_id=1, student_id=1):
> urls.py 
>   url(r'^(?P\d+)/gradings/gradingstudent/(?P\d+)/$', 
> views.grading_student, name='gradingstudent'),
>
> from template :
> if I use :
> a href="{% url 'contest:gradingstudent'  school_id=1 student_id=1 %}"> 
>  Enter Student Score  It work. But when I try to replace 1 by form.instance.id i got error 
> about.
>
>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id=
> form.instance.id %}">  Enter Student Score 
> if I change to this url
>
>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id %}"> {{
> form.instance.id}}  Enter Student Score  I got other error 
>
> Don't mix *args and **kwargs in call to reverse()!
>
> What is the properway to do?
>
>
> Thanks,
>
>
The error is telling you that form.instance.id is None. Presumably this is 
because you are on an add form, and the instance hasn't been created yet - 
in which case you can't link to its contest page.
--
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: and keyword arguments '{u'student_id': None, u'school_id': 1}' not found.

2013-09-21 Thread arjun
And you shouldn't be using id's. using pk is better!

On Saturday, September 21, 2013 9:14:33 AM UTC+5:30, Trung Nguyen wrote:
>
> Django Version:1.5.2Exception Type:NoReverseMatchException Value:
>
> Reverse for 'gradingstudent' with arguments '()' and keyword arguments 
> '{u'student_id': None, u'school_id': 1}' not found.
>
> Exception 
> Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py
>  
> in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4
>  I am new to Django. I got this error and struggle to find a solution for 
> it but no luck. Please help!
>
> View.py   def grading_student(request, school_id=1, student_id=1):
> urls.py 
>   url(r'^(?P\d+)/gradings/gradingstudent/(?P\d+)/$', 
> views.grading_student, name='gradingstudent'),
>
> from template :
> if I use :
> a href="{% url 'contest:gradingstudent'  school_id=1 student_id=1 %}"> 
>  Enter Student Score  It work. But when I try to replace 1 by form.instance.id i got error 
> about.
>
>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id=
> form.instance.id %}">  Enter Student Score 
> if I change to this url
>
>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id %}"> {{
> form.instance.id}}  Enter Student Score  I got other error 
>
> Don't mix *args and **kwargs in call to reverse()!
>
> What is the properway 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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Help with Django installation on windows

2013-09-21 Thread Poom Buncha
Hi all
 
First off, I like to say that I am a beginner to everything related to 
computing. So I have to appologize a head of time if what I am asking is 
common sense.
I'm trying to install Django on my windows computer
 
So I install Python 2.7 (and went throught the tutorial) 
I downloaded the django tar file. and extracted the content using 7zip 
program. 
I did not know where to put it so I put it into the Python folder
 
when I open up a comand prompt for python I type in "import django" 
and "django.get_version()" those commands seem to run fine
but when I type in  
"django-admin.py startproject mysite" I get an error message that say the 
name admin is not define. Can you tell me what I am doing wrong?
 
Thank you for any help you can provide. And if anyone have any tip and best 
practices that they can share with me about getting started in Django it 
will be greatly appreciated
Poom B

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: and keyword arguments '{u'student_id': None, u'school_id': 1}' not found.

2013-09-21 Thread Trung Nguyen
No this not add form and I verify it. I also use pk but it does not work 
either.

On Saturday, September 21, 2013 7:38:52 AM UTC-5, Daniel Roseman wrote:
>
> On Saturday, 21 September 2013 04:44:33 UTC+1, Trung Nguyen wrote:
>
>> Django Version:1.5.2Exception Type:NoReverseMatchException Value:
>>
>> Reverse for 'gradingstudent' with arguments '()' and keyword arguments 
>> '{u'student_id': None, u'school_id': 1}' not found.
>>
>> Exception 
>> Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py
>>  
>> in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4
>>  I am new to Django. I got this error and struggle to find a solution for 
>> it but no luck. Please help!
>>
>> View.py   def grading_student(request, school_id=1, student_id=1):
>> urls.py 
>>   url(r'^(?P\d+)/gradings/gradingstudent/(?P\d+)/$', 
>> views.grading_student, name='gradingstudent'),
>>
>> from template :
>> if I use :
>> a href="{% url 'contest:gradingstudent'  school_id=1 student_id=1 %}"> 
>>  Enter Student Score > It work. But when I try to replace 1 by form.instance.id i got error 
>> about.
>>
>>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id=
>> form.instance.id %}">  Enter Student Score >
>> if I change to this url
>>
>>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id %}"> {{
>> form.instance.id}}  Enter Student Score > I got other error 
>>
>> Don't mix *args and **kwargs in call to reverse()!
>>
>> What is the properway to do?
>>
>>
>> Thanks,
>>
>>
> The error is telling you that form.instance.id is None. Presumably this 
> is because you are on an add form, and the instance hasn't been created yet 
> - in which case you can't link to its contest page.
> --
> DR. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Help with Django installation on windows

2013-09-21 Thread Tom Lockhart

On 2013-09-21, at 1:27 PM, Poom Buncha  wrote:

> Hi all
>  
> First off, I like to say that I am a beginner to everything related to 
> computing. So I have to appologize a head of time if what I am asking is 
> common sense.
> I'm trying to install Django on my windows computer
>  
> So I install Python 2.7 (and went throught the tutorial)
> I downloaded the django tar file. and extracted the content using 7zip 
> program.
> I did not know where to put it so I put it into the Python folder
>  
> when I open up a comand prompt for python I type in "import django" and 
> "django.get_version()" those commands seem to run fine
> but when I type in  
> "django-admin.py startproject mysite" I get an error message that say the 
> name admin is not define. Can you tell me what I am doing wrong?
>  
> Thank you for any help you can provide. And if anyone have any tip and best 
> practices that they can share with me about getting started in Django it will 
> be greatly appreciated
> 

I'm afraid I can't offer specific advice for Windows. But I can recommend that 
you use virtualenv and pip for everything involving python beyond your initial 
python installation. You will find your environment to be more maintainable and 
repeatable.

Good luck!

   - Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Help with Django installation on windows

2013-09-21 Thread Avraham Serour
you should use pip to install python
packages, after you have pip you can use "pip install django"

eventually it is worth to take a look at virtualenv so you can have
separate environments and packages for each project

in any case you should use "python django-admin.py startproject mysite"
assuming python is on path and also django-admin.py
if not you may use the full path for both:

c:\python27\python.exe c:\python27\scripts\django-admin.py



On Sat, Sep 21, 2013 at 11:27 PM, Poom Buncha  wrote:

> Hi all
>
> First off, I like to say that I am a beginner to everything related to
> computing. So I have to appologize a head of time if what I am asking is
> common sense.
> I'm trying to install Django on my windows computer
>
> So I install Python 2.7 (and went throught the tutorial)
> I downloaded the django tar file. and extracted the content using 7zip
> program.
> I did not know where to put it so I put it into the Python folder
>
> when I open up a comand prompt for python I type in "import django"
> and "django.get_version()" those commands seem to run fine
> but when I type in
> "django-admin.py startproject mysite" I get an error message that say the
> name admin is not define. Can you tell me what I am doing wrong?
>
> Thank you for any help you can provide. And if anyone have any tip and
> best practices that they can share with me about getting started in Django
> it will be greatly appreciated
> Poom B
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: and keyword arguments '{u'student_id': None, u'school_id': 1}' not found.

2013-09-21 Thread Trung Nguyen
I found it. Inside {%%} shoud use variable. Inthis case is 
form.instance.id instead of {{form.instance.id}}

On Saturday, September 21, 2013 5:06:07 PM UTC-5, Trung Nguyen wrote:
>
> No this not add form and I verify it. I also use pk but it does not work 
> either.
>
> On Saturday, September 21, 2013 7:38:52 AM UTC-5, Daniel Roseman wrote:
>>
>> On Saturday, 21 September 2013 04:44:33 UTC+1, Trung Nguyen wrote:
>>
>>> Django Version:1.5.2Exception Type:NoReverseMatchException Value:
>>>
>>> Reverse for 'gradingstudent' with arguments '()' and keyword arguments 
>>> '{u'student_id': None, u'school_id': 1}' not found.
>>>
>>> Exception 
>>> Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py
>>>  
>>> in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4
>>>  I am new to Django. I got this error and struggle to find a solution 
>>> for it but no luck. Please help!
>>>
>>> View.py   def grading_student(request, school_id=1, student_id=1):
>>> urls.py 
>>>   url(r'^(?P\d+)/gradings/gradingstudent/(?P\d+)/$', 
>>> views.grading_student, name='gradingstudent'),
>>>
>>> from template :
>>> if I use :
>>> a href="{% url 'contest:gradingstudent'  school_id=1 student_id=1 %}"> 
>>>  Enter Student Score >> It work. But when I try to replace 1 by form.instance.id i got error 
>>> about.
>>>
>>>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id=
>>> form.instance.id %}">  Enter Student Score >>
>>> if I change to this url
>>>
>>>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id %}"> {{
>>> form.instance.id}}  Enter Student Score >> I got other error 
>>>
>>> Don't mix *args and **kwargs in call to reverse()!
>>>
>>> What is the properway to do?
>>>
>>>
>>> Thanks,
>>>
>>>
>> The error is telling you that form.instance.id is None. Presumably this 
>> is because you are on an add form, and the instance hasn't been created yet 
>> - in which case you can't link to its contest page.
>> --
>> DR. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: and keyword arguments '{u'student_id': None, u'school_id': 1}' not found.

2013-09-21 Thread Trung Nguyen


On Friday, September 20, 2013 10:44:33 PM UTC-5, Trung Nguyen wrote:
>
> Django Version:1.5.2Exception Type:NoReverseMatchException Value:
>
> Reverse for 'gradingstudent' with arguments '()' and keyword arguments 
> '{u'student_id': None, u'school_id': 1}' not found.
>
> Exception 
> Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py
>  
> in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4
>  I am new to Django. I got this error and struggle to find a solution for 
> it but no luck. Please help!
>
> View.py   def grading_student(request, school_id=1, student_id=1):
> urls.py 
>   url(r'^(?P\d+)/gradings/gradingstudent/(?P\d+)/$', 
> views.grading_student, name='gradingstudent'),
>
> from template :
> if I use :
> a href="{% url 'contest:gradingstudent'  school_id=1 student_id=1 %}"> 
>  Enter Student Score  It work. But when I try to replace 1 by form.instance.id i got error 
> about.
>
>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id=
> form.instance.id %}">  Enter Student Score 
> if I change to this url
>
>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id %}"> {{
> form.instance.id}}  Enter Student Score  I got other error 
>
> Don't mix *args and **kwargs in call to reverse()!
>
> What is the properway 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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Help with Django installation on windows

2013-09-21 Thread Poom Buncha

>
> I see, thank you for your quick reply I will try Virtualenv and pip
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Help with Django installation on windows

2013-09-21 Thread Chris Kavanagh
Hi Poom. . .You need to make sure that Django AND Python are on your system 
path. I'll run you through how to do that. . .Right click on "My Computer", 
choose "Properties", on the "Properties Window" choose the "Advanced Tab", 
then choose "Environment Variable". In that window it'll be divided into 2 
different sections, you want the one that says "System Variables". Locate 
the entry that says "Path", click on it to highlight, then choose "Edit". 
Another window will open with your system paths in it highlighted (be 
careful to NOT hit delete!!!), click on it so it's no longer highlighted 
and use the right arrow key to get to the end. Put a semi colon after the 
last entry (semi colon separates each entry), then you need to add your 
python path. For instance mine is "C:\Python27" and to be safe (can't 
remember if this is required) put your path to "Scripts", in other words 
mine is "C:\Python27\Scripts\". . .Now you have to add the path to the 
django lib, which in my case is 
"C:\Python27\django-chris\Lib\site-packages\django-1.5.1-py2.7.egg\django\bin". 
That should solve your problem. In my sys path I've also included 
"C:\Python27\django-chris" which is the path to my project. .Not sure if 
that's necessary or not, but it won't hurt to put it in there.

Here's a good article explaining this on 
"http://wiki.thinkhole.org/howto:django_on_windows"; and 
"http://tavisharmstrong.com/2011/01/19/how-to-install-python-and-django-on-windows/";.
 
. .Like others said, you need to get pip and or easy_intall loaded for 
Python, because it will allow you to EASILY add things like Django and 
other packages. Just google the instructions for that. . .I hope this 
helps. If not , just post your what happens and I'll help yoy.


%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program 
Files\ATI Technologies\ATI Control Panel;C:\Documents and Settings\Chris 
Kavanagh\Desktop\emacs-24.3-bin-i386\emacs-24.3\bin;C:\Python27;C:\Python27\Scripts\;%HOMEPATH%\.emacs.d;C:\Documents
 
and Settings\Chris 
Kavanagh\Desktop\emacs-24.3-bin-i386\emacs-24.3\bin;C:\Documents and 
Settings\Chris 
Kavanagh\.emacs.d\elpa;C:\Python27\django-chris\Lib\site-packages\django-1.5.1-py2.7.egg\django\bin;C:\Python27\django-chris\Lib\site-packages\django-1.5.1-py2.7.egg;C:\Python27\django-chris\Lib\site-packages\django-1.5.1-py2.7.egg\django;C:\Python27\django-chris\Lib\site-packages\django-1.5.1-py2.7.egg\django\bin;C:\Python27\django-chris

On Saturday, September 21, 2013 4:27:33 PM UTC-4, Poom Buncha wrote:
>
> Hi all
>  
> First off, I like to say that I am a beginner to everything related to 
> computing. So I have to appologize a head of time if what I am asking is 
> common sense.
> I'm trying to install Django on my windows computer
>  
> So I install Python 2.7 (and went throught the tutorial) 
> I downloaded the django tar file. and extracted the content using 7zip 
> program. 
> I did not know where to put it so I put it into the Python folder
>  
> when I open up a comand prompt for python I type in "import django" 
> and "django.get_version()" those commands seem to run fine
> but when I type in  
> "django-admin.py startproject mysite" I get an error message that say the 
> name admin is not define. Can you tell me what I am doing wrong?
>  
> Thank you for any help you can provide. And if anyone have any tip and 
> best practices that they can share with me about getting started in Django 
> it will be greatly appreciated
> Poom B
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Django admin - dinamically update through ajax choices of a ChoiceField in a ModelForm

2013-09-21 Thread luke lukes
Hi everyone.

I'm stucking with a ModelForm in the admin. I have two ChoicheField which 
are populated with choices in __init__:

self.fields['city'] = forms.ChoiceField(
required=False,
)
self.fields['city'].choices=get_cities_tuple(region_code=region_code)
self.fields['city'].initial = my_initial_city_value

self.fields['zip'] = forms.ChoiceField(
required=False,
)
self.fields['zip'].choices=get_cities_tuple(region_code=region_code, 
city_name=city_name)
self.fields['zip'].initial = my_initial_zip_value


now the options of those html select rendered are dinamically updated 
through ajax functions. 
The problem is that while saving, the selected options is recognized as not 
valid cause is not in the initial choices:

Select a valid choice.  is not one of the available choices.

Any idea on how to solve it? 

Maybe subclassing the original ChoiceField or the Select widget?

Many thanks
LuKe

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Overriding Settings before running any tests that loads fixtures.

2013-09-21 Thread Alex Thomas
My basic problem is that I am trying to run a test that loads fixtures but 
I want to modify some settings before the fixtures are loaded.  

I tried adding override_settings decorator on the class but it does not see 
to take effect before the fixtures are loaded.  
I also posted the question here if you want more detail:  
http://stackoverflow.com/questions/18927935/what-is-the-order-of-execution-in-django-tests



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


I can run django-admin.py, but not manage.py.

2013-09-21 Thread Jimmy Pants
Noob here. I installed Django, and as the title says, I can run 
django-admin without a problem, but manage.py gives:

$ manage.py
manage.py: command not found

 $ ./manage.py
bash: ./manage.py: Permission denied

 $ sudo ./manage.py
[sudo] password for me: 
sudo: ./manage.py: command not found


Is this a permissions issue (Linux Mint here), or wtf? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I can run django-admin.py, but not manage.py.

2013-09-21 Thread Oscar Carballal
The manage.py is not executable by default, you should be running it with:

$ python manage.py

or if you want it to be executable forever and run it with ./manage.py do:

$ chmod +x manage.py


2013/9/22 Jimmy Pants 

> Noob here. I installed Django, and as the title says, I can run
> django-admin without a problem, but manage.py gives:
>
> $ manage.py
> manage.py: command not found
>
>  $ ./manage.py
> bash: ./manage.py: Permission denied
>
>  $ sudo ./manage.py
> [sudo] password for me:
> sudo: ./manage.py: command not found
>
>
> Is this a permissions issue (Linux Mint here), or wtf?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Overriding Settings before running any tests that loads fixtures.

2013-09-21 Thread Mike Dewhirst

On 22/09/2013 9:47am, Alex Thomas wrote:

My basic problem is that I am trying to run a test that loads fixtures
but I want to modify some settings before the fixtures are loaded.


Check out Two Scoops of Django - there is a whole chapter on this.

Esssntially you need some test settings which only run with your tests. 
It is done by importing your main settings and overriding those of 
interest when testing.





I tried adding override_settings decorator on the class but it does not
see to take effect before the fixtures are loaded.
I also posted the question here if you want more detail:
http://stackoverflow.com/questions/18927935/what-is-the-order-of-execution-in-django-tests



--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: and keyword arguments '{u'student_id': None, u'school_id': 1}' not found.

2013-09-21 Thread Trung Nguyen

If I pass in a variable to the template like 

 return render_to_response("grading_school_form.html",  
RequestContext(request, { "formset": formset, "pk":school_id, "spk":1}))
 
then in the template 
  
   {% for form in formset %}


   {{ spk }}
 {{ form.first_name }}
{{ form.last_name}}
 {{ form.schoolName }}
Enter Student Score 

{% endfor %}

It does work.

But i need to dynamicly assign the form ID  to the student id like 
student_id= form.instanse.pk
then it complain
like 

everse for 'gradingstudent' with arguments '()' and keyword arguments 
'{u'student_id': None, u'school_id': 1}' not found.


when i try to assign spk = form.instanse.pk
like
{% with form.instance.id.to_int as spk%}

   {{ spk }}
 {{ form.first_name }}
{{ form.last_name}}
 {{ form.schoolName }}
Enter Student Score 
{% endwith %}

 
On Saturday, September 21, 2013 5:06:07 PM UTC-5, Trung Nguyen wrote:
>
> No this not add form and I verify it. I also use pk but it does not work 
> either.
>
> On Saturday, September 21, 2013 7:38:52 AM UTC-5, Daniel Roseman wrote:
>>
>> On Saturday, 21 September 2013 04:44:33 UTC+1, Trung Nguyen wrote:
>>
>>> Django Version:1.5.2Exception Type:NoReverseMatchException Value:
>>>
>>> Reverse for 'gradingstudent' with arguments '()' and keyword arguments 
>>> '{u'student_id': None, u'school_id': 1}' not found.
>>>
>>> Exception 
>>> Location:/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py
>>>  
>>> in render, line 424Python Executable:/usr/bin/pythonPython Version:2.7.4
>>>  I am new to Django. I got this error and struggle to find a solution 
>>> for it but no luck. Please help!
>>>
>>> View.py   def grading_student(request, school_id=1, student_id=1):
>>> urls.py 
>>>   url(r'^(?P\d+)/gradings/gradingstudent/(?P\d+)/$', 
>>> views.grading_student, name='gradingstudent'),
>>>
>>> from template :
>>> if I use :
>>> a href="{% url 'contest:gradingstudent'  school_id=1 student_id=1 %}"> 
>>>  Enter Student Score >> It work. But when I try to replace 1 by form.instance.id i got error 
>>> about.
>>>
>>>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id=
>>> form.instance.id %}">  Enter Student Score >>
>>> if I change to this url
>>>
>>>  a href="{% url 'contest:gradingstudent'  school_id=1 student_id %}"> {{
>>> form.instance.id}}  Enter Student Score >> I got other error 
>>>
>>> Don't mix *args and **kwargs in call to reverse()!
>>>
>>> What is the properway to do?
>>>
>>>
>>> Thanks,
>>>
>>>
>> The error is telling you that form.instance.id is None. Presumably this 
>> is because you are on an add form, and the instance hasn't been created yet 
>> - in which case you can't link to its contest page.
>> --
>> DR. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django admin - dinamically update through ajax choices of a ChoiceField in a ModelForm

2013-09-21 Thread C. Kirby
If you can, populate the widget with all available choices and then use 
your JS/AJAX to limit/hide some?



On Saturday, September 21, 2013 6:32:03 PM UTC-5, luke lukes wrote:
>
> Hi everyone.
>
> I'm stucking with a ModelForm in the admin. I have two ChoicheField which 
> are populated with choices in __init__:
>
> self.fields['city'] = forms.ChoiceField(
> required=False,
> )
> self.fields['city'].choices=get_cities_tuple(region_code=region_code)
> self.fields['city'].initial = my_initial_city_value
>
> self.fields['zip'] = forms.ChoiceField(
> required=False,
> )
> self.fields['zip'].choices=get_cities_tuple(region_code=region_code, 
> city_name=city_name)
> self.fields['zip'].initial = my_initial_zip_value
>
>
> now the options of those html select rendered are dinamically updated 
> through ajax functions. 
> The problem is that while saving, the selected options is recognized as 
> not valid cause is not in the initial choices:
>
> Select a valid choice.  is not one of the available choices.
>
> Any idea on how to solve it? 
>
> Maybe subclassing the original ChoiceField or the Select widget?
>
> Many thanks
> LuKe
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.