How to make a subscription form for use with Stripe / dj-stripe?

2017-12-04 Thread Daniel Grace
I have set up a Stripe account and installed dj-stripe, but I can't find 
information on how to set up a subscription form.  I understand that 
dj-stripe looks for a template in the djstripe directory, but I don't know 
what should be in the template.

-- 
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/db194ef1-96f7-4e5d-9c6e-994a808766be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to hook into the admin site to count login attempts with REST API / proxy?

2016-11-04 Thread Daniel Grace
Hello, I have a REST API which is not publicly accessible as it is behind a 
proxy.  However the admin site is publicly available through an NGINX 
server.  The REST API already has functionality to count failed login 
attempts and I would like to duplicate that functionality on the admin 
login page.  How do I hook into the admin login page and add the 
appropriate code?  Can I still use Django Axes or should I create my own 
login form as a replacement?
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/69ea593b-4c5e-4eb6-ab9f-fa4639d17445%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do you access the HTTP data in a view derived from the generic View class?

2015-08-20 Thread Daniel Grace
I found the answer to this is to look at request.POST.

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


How do you access the HTTP data in a view derived from the generic View class?

2015-08-20 Thread Daniel Grace
Suppose I have a view as follows:

from django.views.generic import View
from django.http import HttpResponse
from braces.views import CsrfExemptMixin

class TestView(CsrfExemptMixin, View):
def post(self, request, *args, **kwargs):
# how to access the HTTP data here?
return HttpResponse(content='some response', status=200)

... and I want to access the data "12345" and "abcde" as in the command:
curl -X POST http://localhost:8000/test/ -d "foo=12345&bar=abcde"

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2ee2e83b-c240-492a-96f8-e3781e269710%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Error when checking owner in REST API CreateAPIView

2015-07-09 Thread Daniel Grace
With CreateAPIView from the REST API I am trying to stop users from 
creating data in another users name.

In models.py:
class UserData(models.Model):
user = models.OneToOneField(User, db_index=True, 
related_name='userdata', blank=False, null=False)
textdata = models.TextField(blank=True, null=True)

In views.py:
class UserDataCreateView(generics.CreateAPIView):
permission_classes = [permissions.IsAuthenticated]
serializer_class = UserDataSerializer
queryset = UserData.objects.all()
def create(self, request, *args, **kwargs):
instance = self.get_object()
if instance.user != request.user:
raise PermissionDenied
return super(UserDataCreateView, self).create(request, *args, 
**kwargs)

Gives the error:
Expected view UserDataCreateView to be called with a URL keyword argument 
named "pk". Fix your URL conf, or set the `.lookup_field` attribute on the 
view correctly.

What am I doing wrong?  Alternatively, how would I set the user ID on the 
newly created record without saving twice (which would not be a good idea) ?

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


Re: How to protect a view with client ID and client secret in REST / oauth toolkit?

2015-07-07 Thread Daniel Grace
I guess there are more standard ways of protecting a view.

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


How to protect a view with client ID and client secret in REST / oauth toolkit?

2015-07-06 Thread Daniel Grace
Say I have a REST view:

class CreateUserView(generics.CreateAPIView):
serializer_class = CreateUserSerializer
queryset = User.objects.all()

...how is it possible to protect the view with the client ID and client 
secret from the oauth toolkit?

So that I can invoke the view via a special request like:
curl -X POST http://127.0.0.1:8000/user-create/ -d 
"client_id=&client_secret=&username=andrew&password=andrew&first_name=Andrew&last_name=Bonvix"

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/51dde18e-8cbf-4df8-af58-013bc93f9b8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Where does django-rest-framework-social-oauth2 create Django user accounts?

2015-07-05 Thread Daniel Grace
Where in the source code does django-rest-framework-social-oauth2 (which 
uses django-oauth-toolkit and python-social-auth) auto create Django user 
accounts?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/714d8c2a-863e-4283-81c0-3962ca03e99c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to restrict update of a record to the record owner in Django REST?

2015-07-04 Thread Daniel Grace
I found a solution based on the example in REST API guide:
http://www.django-rest-framework.org/api-guide/permissions/#examples

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ad0235e4-87d9-450e-be7e-44b965b65e13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to restrict update of a record to the record owner in Django REST?

2015-07-04 Thread Daniel Grace
I want to restrict update of a record to the record owner in an 
UpdateAPIView with Django REST, but I don't know how to code the method.

For example, something like this:

from rest_framework import generics
from testapp.serializers import UserProfileSerializer
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import permissions
from oauth2_provider.ext.rest_framework import TokenHasReadWriteScope

class UserProfileView(generics.UpdateAPIView):
permission_classes = [permissions.IsAuthenticated, 
TokenHasReadWriteScope]
serializer_class = UserProfileSerializer
queryset = UserProfile.objects.all()
# patch method?
# if UserProfile user != self.request.user:
# raise exceptions.PermissionDenied
# else:
# continue as normal

Where "user" is a field on the UserProfile model.

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


How to protect a REST API view with token authentication using django-rest-framework-social-oauth2?

2015-06-27 Thread Daniel Grace
I have installed and setup the django-rest-framework-social-oauth2 package. 
 Now I need to protect my REST API views with the appropriate token 
authentication.  Do I follow the method at:
http://www.django-rest-framework.org/api-guide/authentication/#tokenauthentication
 
or is another method appropriate?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c5d4567f-878b-4372-b64e-1d33752bc045%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error when adding application record for django-rest-framework-social-oauth2

2015-06-25 Thread Daniel Grace
OK, I sussed this.  I entered "1" for the user field, the form was then 
valid and the record saved to the database.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7e1760ac-26ab-47c6-b609-7f6a458dea2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Error when adding application record for django-rest-framework-social-oauth2

2015-06-25 Thread Daniel Grace
I am following the instructions for django-rest-framework-social-oauth2 
at https://pypi.python.org/pypi/django-rest-framework-social-oauth2/0.0.4

When I attempt to add an application record via "Home › Oauth2_Provider › 
Applications › Add application", I get the error message "Select a valid 
choice. That choice is not one of the available choices."  This error 
appears to be on the user field, where I specified the Django superuser 
"daniel".

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2fcd27e8-3127-493b-8f2a-c4a2e31554d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error using django-rest-framework-social-oauth2

2015-06-23 Thread Daniel Grace
OK, my mistake, I ran migrate again and got the neccessary tables.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b155f3b8-6555-430b-bc2d-1819560b48ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Error using django-rest-framework-social-oauth2

2015-06-23 Thread Daniel Grace
I have installed and set up django-rest-framework-social-oauth2, as per 
instructions 
on: https://pypi.python.org/pypi/django-rest-framework-social-oauth2/0.0.4
I did makemigrations and migrate, but there were no extra tables... when I 
go to "Django administration - Site administration" and click on "Access 
tokens" under "Oauth2_Provider" I get the error:
Request Method: GET
Request URL: http://localhost:8000/admin/oauth2_provider/accesstoken/
Django Version: 1.8.2
Exception Type: ProgrammingError
Exception Value: 
relation "oauth2_provider_accesstoken" does not exist
LINE 1: SELECT COUNT('*') AS "__count" FROM "oauth2_provider_accesst...

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


django-rest-auth with django-allauth not what I was expecting

2015-06-23 Thread Daniel Grace
I am trying to write a Django / REST API back end with Facebook 
authentication, for use with a phone app front end. I installed and 
configured both django-rest-auth and django-allauth.  When testing I can 
log into Facebook and authorise my app to access my Facebook account, OK. 
 But then I am faced with a HTML form for specifying a Django user name, I 
was expecting a REST API request for this information.  Is there a 
reasonable way to configure these packages so that all the communications 
are via REST? (Am I misunderstanding something?)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5918e090-bf3f-460f-b32f-f50a8499c6e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Errors with django-rest-auth and django-allauth

2015-06-20 Thread Daniel Grace
I have installed Django (1.8), django-allauth (0.20.0) django-rest-auth 
(0.4.0).

I added to INSTALLED_APPS in settings.py:
'rest_framework',
'rest_framework.authtoken',
'rest_auth'
'allauth',
'allauth.account',
'rest_auth.registration',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',

And I added to TEMPLATES - OPTIONS - context_processors in settings.py:
'django.core.context_processors.request',
'allauth.account.context_processors.account',
'allauth.socialaccount.context_processors.socialaccount',

When I run the server (python manage.py runserver) I get several errors:
C:\Users\Daniel\venvs\castle\lib\site-packages\django\contrib\sites\models.py:78
: RemovedInDjango19Warning: Model class django.contrib.sites.models.Site 
doesn't
 declare an explicit app_label and either isn't in an application in 
INSTALLED_A
PPS or else was imported before its application was loaded. This will no 
longer
be supported in Django 1.9.
  class Site(models.Model):

C:\Users\Daniel\venvs\castle\lib\site-packages\django\contrib\sites\models.py:78
: RemovedInDjango19Warning: Model class django.contrib.sites.models.Site 
doesn't
 declare an explicit app_label and either isn't in an application in 
INSTALLED_A
PPS or else was imported before its application was loaded. This will no 
longer
be supported in Django 1.9.
  class Site(models.Model):

Performing system checks...

Unhandled exception in thread started by .wrapper
 at 0x0438DBF8>
Traceback (most recent call last):
  File 
"C:\Users\Daniel\venvs\castle\lib\site-packages\django\utils\autoreload.p
y", line 223, in wrapper
fn(*args, **kwargs)
  File 
"C:\Users\Daniel\venvs\castle\lib\site-packages\django\core\management\co
mmands\runserver.py", line 110, in inner_run
self.validate(display_num_errors=True)
  File 
"C:\Users\Daniel\venvs\castle\lib\site-packages\django\core\management\ba
se.py", line 465, in validate
return self.check(app_configs=app_configs, 
display_num_errors=display_num_er
rors)
  File 
"C:\Users\Daniel\venvs\castle\lib\site-packages\django\core\management\ba
se.py", line 524, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System 
check ide
ntified some issues:

ERRORS:
socialaccount.SocialApp.sites: (fields.E300) Field defines a relation with 
model
 'Site', which is either not installed, or is abstract

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/826d3374-9eb3-4067-93e2-6be3e7bbe805%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Preferred way of adding social authorization to a Django / REST app?

2015-06-18 Thread Daniel Grace
What is the preferred way of adding social authorization to a Django / REST 
app?

I see that there are at least two packages: 
django-rest-framework-social-oauth2 (see 
https://pypi.python.org/pypi/django-rest-framework-social-oauth2/0.0.4) 
and django-rest-auth (see 
http://django-rest-auth.readthedocs.org/en/latest/installation.html). 
 django-rest-framework-social-oauth2 seems to have a lot of dependencies. 
 While the install page for django-rest-auth says that you should 
install rest_framework and rest_framework.authtoken apps, both of which 
give an error if you try to install them with pip:

Downloading/unpacking rest-framework.authtoken
  Could not find any downloads that satisfy the requirement 
rest-framework.authtoken
Cleaning up...
No distributions at all found for rest-framework.authtoken
Storing debug log for failure in C:\Users\Daniel\pip\pip.log

Or is there a better alternative to these two packages for Django / REST / 
social authorization apps?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8637f6fa-7241-4866-9a52-311b36f5d8be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to serialize one record with Django / REST?

2015-06-14 Thread Daniel Grace
I can serialize all objects using the following.  In views:

class ProductDetail(generics.ListAPIView):
serializer_class = ProductSerializer
def get_queryset(self):
return Product.objects.all()

In serializers:

class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields = ('code', 'name', 'description')

When I try to restrict this to one record, I get an error:

class ProductDetail(generics.RetrieveAPIView):
serializer_class = ProductSerializer
def get_queryset(self):
pid = int(self.kwargs['pid'])
return Product.objects.get(id=pid)

Exception Type: AttributeError
Exception Value:'Product' object has no attribute 'model'

I am guessing that get_queryset is not the right thing to use in this 
situation.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1a4a658e-4728-4577-a0f6-9fdd5e110f09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why the extra minute in PostgreSQL when using time zone info?

2015-05-28 Thread Daniel Grace
I used this function, seemed to tidy up the problem:

from datetime import datetime
from pytz import timezone

def utcDtTm(self, dt_tm):
tz = timezone('Europe/London')
return tz.normalize(tz.localize(dt_tm)).astimezone(timezone('UTC'))

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12a0ab90-8108-46b4-8e90-5aadedbb3d2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Why the extra minute in PostgreSQL when using time zone info?

2015-05-28 Thread Daniel Grace
I am creating some test data for a DateTimeField using the following 
function:

def rndDtTm(self):
uktz = timezone('Europe/London')
year = 2015
month = 6
day = randint(1, 30)
hour = randint(0, 23)
minute = 30 * randint(0, 1)
return datetime(year, month, day, hour, minute, 0, 0, tzinfo = uktz)

When I look at the PostgreSQL field in pgAdminIII the times are either 1 or 
31 minutes past the hour:
2015-06-10 22:01:00+01
2015-06-12 21:31:00+01

I was expecting them to be 0 or 30 minutes past the hour.  Why the extra 
minute?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/156ff7ce-9252-4384-9eaa-7e4b23a3880c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to create a multi valued field in the model?

2015-03-23 Thread Daniel Grace
How to create a field with multiple values?  For example an integer field 
that takes on particular values:

state = models.IntegerField()

... where state=0 represents 'pending', state=1 represents 'accepted' and 
state=2 represents 'rejected'.
Is it possible to put these values / constants into the model?

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


Re: What on earth is causing this "naive datetime" warning?

2014-11-19 Thread Daniel Grace

>
>
> But based on your traceback, it seems like at some point in the past 
> when you made a migration, the field might have had a default value 
> which was a naive datetime. Is that possible? 
>
> It might be necessary to look through your existing migrations for this 
> app to find the culprit. 
>
>
Yes Carl you were right, I cleared out my migrations folder except for the 
"__init__.py" file and the problem went away. 

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


Re: What on earth is causing this "naive datetime" warning?

2014-11-19 Thread Daniel Grace
On Wednesday, 19 November 2014 15:11:27 UTC, Carl Meyer wrote:
>
> Hi Daniel, 
>
> On 11/19/2014 08:07 AM, Daniel Grace wrote: 
> > I have already installed pytz (2014.17) and I have set USE_TZ=True.  I 
> > don't use any naive datetimes in my application.  This error is caused 
> > by something that the Django test command is doing automatically, if you 
> > look at the traceback you will see that it is something to do with 
> > migrations.  I am using Django 1.7. 
>
> What is the default value for your Flow.created field? 
>
> Carl 
>
>
Hi Carl,
I was not specifying one, so I changed my model and did a "makemigrations" 
and a "syncdb" :

class Flow(models.Model):
ref = models.CharField(max_length=32)
state = models.ForeignKey(State)
flow_type = models.ForeignKey(Type)
created = models.DateTimeField(db_index=True, auto_now_add=True, 
default=timezone.now)
modified = models.DateTimeField(db_index=True, auto_now=True, 
default=timezone.now)
version = models.IntegerField()

But I still get the exact same warning (see my original message in this 
thread) !

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/99783c9d-fe30-44cf-b407-53ad804e3ecb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: What on earth is causing this "naive datetime" warning?

2014-11-19 Thread Daniel Grace
I have already installed pytz (2014.17) and I have set USE_TZ=True.  I 
don't use any naive datetimes in my application.  This error is caused by 
something that the Django test command is doing automatically, if you look 
at the traceback you will see that it is something to do with migrations. 
 I am using Django 1.7.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/091b1229-69c1-47aa-b0ba-ee986922a7c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


What on earth is causing this "naive datetime" warning?

2014-11-19 Thread Daniel Grace
Hi,

Here is my model:
class Flow(models.Model):
ref = models.CharField(max_length=32)
state = models.ForeignKey(State)
flow_type = models.ForeignKey(Type)
created = models.DateTimeField(db_index=True, auto_now_add=True)
modified = models.DateTimeField(db_index=True, auto_now=True)
version = models.IntegerField()
def __str__(self):
return str(self.id)

Here is my test.py file:
import warnings
warnings.filterwarnings(
'error', r"DateTimeField .* received a naive datetime",
RuntimeWarning, r'django\.db\.models\.fields')


In settings.py:
TIME_ZONE = 'Europe/London'
USE_TZ = True

Here is what happens when I run the test script:
>python manage.py test flow
Creating test database for alias 'default'...
Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File "C:\landy\lib\site-packages\django\core\management\__init__.py", 
line 385
, in execute_from_command_line
utility.execute()
  File "C:\landy\lib\site-packages\django\core\management\__init__.py", 
line 377
, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"C:\landy\lib\site-packages\django\core\management\commands\test.py", lin
e 50, in run_from_argv
super(Command, self).run_from_argv(argv)
  File "C:\landy\lib\site-packages\django\core\management\base.py", line 
288, in
 run_from_argv
self.execute(*args, **options.__dict__)
  File 
"C:\landy\lib\site-packages\django\core\management\commands\test.py", lin
e 71, in execute
super(Command, self).execute(*args, **options)
  File "C:\landy\lib\site-packages\django\core\management\base.py", line 
338, in
 execute
output = self.handle(*args, **options)
  File 
"C:\landy\lib\site-packages\django\core\management\commands\test.py", lin
e 88, in handle
failures = test_runner.run_tests(test_labels)
  File "C:\landy\lib\site-packages\django\test\runner.py", line 147, in 
run_test
s
old_config = self.setup_databases()
  File "C:\landy\lib\site-packages\django\test\runner.py", line 109, in 
setup_da
tabases
return setup_databases(self.verbosity, self.interactive, **kwargs)
  File "C:\landy\lib\site-packages\django\test\runner.py", line 299, in 
setup_da
tabases
serialize=connection.settings_dict.get("TEST_SERIALIZE", True),
  File "C:\landy\lib\site-packages\django\db\backends\creation.py", line 
374, in
 create_test_db
test_flush=True,
  File "C:\landy\lib\site-packages\django\core\management\__init__.py", 
line 115
, in call_command
return klass.execute(*args, **defaults)
  File "C:\landy\lib\site-packages\django\core\management\base.py", line 
338, in
 execute
output = self.handle(*args, **options)
  File 
"C:\landy\lib\site-packages\django\core\management\commands\migrate.py",
line 160, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
  File "C:\landy\lib\site-packages\django\db\migrations\executor.py", line 
63, i
n migrate
self.apply_migration(migration, fake=fake)
  File "C:\landy\lib\site-packages\django\db\migrations\executor.py", line 
97, i
n apply_migration
migration.apply(project_state, schema_editor)
  File "C:\landy\lib\site-packages\django\db\migrations\migration.py", line 
107,
 in apply
operation.database_forwards(self.app_label, schema_editor, 
project_state, ne
w_state)
  File 
"C:\landy\lib\site-packages\django\db\migrations\operations\fields.py", l
ine 131, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
  File "C:\landy\lib\site-packages\django\db\backends\schema.py", line 509, 
in a
lter_field
self._alter_field(model, old_field, new_field, old_type, new_type, 
old_db_pa
rams, new_db_params, strict)
  File "C:\landy\lib\site-packages\django\db\backends\schema.py", line 612, 
in _
alter_field
new_default = self.effective_default(new_field)
  File "C:\landy\lib\site-packages\django\db\backends\schema.py", line 183, 
in e
ffective_default
default = field.get_db_prep_save(default, self.connection)
  File "C:\landy\lib\site-packages\django\db\models\fields\__init__.py", 
line 62
7, in get_db_prep_save
prepared=False)
  File "C:\landy\lib\site-packages\django\db\models\fields\__init__.py", 
line 12
86, in get_db_prep_value
value = self.get_prep_value(value)
  File "C:\landy\lib\site-packages\django\db\models\fields\__init__.py", 
line 12
78, in get_prep_value
RuntimeWarning)
RuntimeWarning: DateTimeField Flow.created received a naive datetime 
(2014-11-19
 12:28:38.831258) while time zone support is active.

What on earth is causing this "naive datetime" warning?

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.

Warning / Error when testing with W flag

2014-11-18 Thread Daniel Grace
Hi,
I get another warning / error with a test command as follows:
>python -W error manage.py test flow
Traceback (most recent call last):
  File "manage.py", line 8, in 
from django.core.management import execute_from_command_line
  File "C:\landy\lib\site-packages\django\core\management\__init__.py", 
line 8,
in 
from django.apps import apps
  File "C:\landy\lib\site-packages\django\apps\__init__.py", line 1, in 


from .config import AppConfig   # NOQA
  File "C:\landy\lib\site-packages\django\apps\config.py", line 5, in 

from django.utils.module_loading import module_has_submodule
  File "C:\landy\lib\site-packages\django\utils\module_loading.py", line 4, 
in <
module>
import imp
  File "C:\Python34\lib\imp.py", line 32, in 
PendingDeprecationWarning)
PendingDeprecationWarning: the imp module is deprecated in favour of 
importlib;
see the module's documentation for alternative uses

Any ideas?

Thanks

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


Re: Runtime warning about a naive datetime when running the test command

2014-11-17 Thread Daniel Grace
On Monday, 17 November 2014 11:33:40 UTC, Bruno Barcarol Guimarães wrote:
>
>
> $ python -W error manage.py test
>
>  
Hi Bruno,
I get another warning / error with that command:
>python -W error manage.py test flow
Traceback (most recent call last):
  File "manage.py", line 8, in 
from django.core.management import execute_from_command_line
  File "C:\landy\lib\site-packages\django\core\management\__init__.py", 
line 8,
in 
from django.apps import apps
  File "C:\landy\lib\site-packages\django\apps\__init__.py", line 1, in 


from .config import AppConfig   # NOQA
  File "C:\landy\lib\site-packages\django\apps\config.py", line 5, in 

from django.utils.module_loading import module_has_submodule
  File "C:\landy\lib\site-packages\django\utils\module_loading.py", line 4, 
in <
module>
import imp
  File "C:\Python34\lib\imp.py", line 32, in 
PendingDeprecationWarning)
PendingDeprecationWarning: the imp module is deprecated in favour of 
importlib;
see the module's documentation for alternative uses

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/45eef407-09f0-4cc2-bbdd-603d1a0424c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Runtime warning about a naive datetime when running the test command

2014-11-16 Thread Daniel Grace
Is this a bug in the Django tester?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f01bdb67-3dbe-43e4-922b-62c14da92094%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Runtime warning about a naive datetime when running the test command

2014-11-16 Thread Daniel Grace
I understand the problem.  Why doesn't the Django tester provide time zone 
aware date times?  I know if I set "USE_TZ = False" the warnings will 
disappear.  I was looking for another solution.  Could I conditionally 
set "USE_TZ = False" only when testing?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/920494f3-6129-48fd-9374-9901287fca3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Runtime warning about a naive datetime when running the test command

2014-11-15 Thread Daniel Grace
Hi,
I get a runtime warning about a naive datetime when running the test 
command:
>python manage.py test flow

Creating test database for alias 'default'...
C:\landy\lib\site-packages\django\db\models\fields\__init__.py:1278: 
RuntimeWarn
ing: DateTimeField Flow.created received a naive datetime (2014-11-15 
13:58:10.2
28817) while time zone support is active.
  RuntimeWarning)

Here is the field in the model:
class Flow(models.Model):
...
created = models.DateTimeField(db_index=True, auto_now_add=True)

And in settings.py I have:
TIME_ZONE = 'Europe/London'
USE_TZ = True

I don't get these warnings when manually testing the application.  What is 
going on?

Thanks

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


Re: Database "postgres" does not exist error when running test command

2014-11-15 Thread Daniel Grace
On Saturday, 15 November 2014 00:58:32 UTC, Aliane Abdelouahab wrote:
>
> how about this
> http://stackoverflow.com/a/19426770/861487
>
>
That link, what is that about?

Anyway, I manually created a database called "postgres" and the error went 
away.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/69494b21-744d-471c-b6c0-eedec41ed6ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Database "postgres" does not exist error when running test command

2014-11-14 Thread Daniel Grace
Hi,
I get an error when running the test command:
>python manage.py test flow

Creating test database for alias 'default'...
Traceback (most recent call last):
  File "C:\landy\lib\site-packages\django\db\backends\__init__.py", line 
133, in
 ensure_connection
self.connect()
  File "C:\landy\lib\site-packages\django\db\backends\__init__.py", line 
122, in
 connect
self.connection = self.get_new_connection(conn_params)
  File 
"C:\landy\lib\site-packages\django\db\backends\postgresql_psycopg2\base.p
y", line 134, in get_new_connection
return Database.connect(**conn_params)
  File "C:\landy\lib\site-packages\psycopg2\__init__.py", line 164, in 
connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATAL:  database "postgres" does not exist

Here is the database settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'cresta',  
'USER': 'postgres',
'PASSWORD': 'test1234',
'HOST': '',
'ATOMIC_REQUESTS': True
}
}

I don't get any errors when manually testing.  What is going on?

Thanks

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


Forms / pages and CSS like Django admin

2014-11-06 Thread Daniel Grace
Hi,
OK, I know how to import CSS into a template.  I would like to get forms / 
pages that look like those on Django admin site.  What is a good strategy 
to achieve this? Copy the CSS?  Looking at "inspect element" in Google 
Chrome I see that the styling on the forms in the Django admin site do not 
always use tables.  In particular I would like the same fonts and table 
styling as on the admin pages.  So how do I get alignment of elements, so 
the left of the form inputs or fields are horizontally aligned?  I am aware 
of CSS and HTML tables, but not sure about other ways of achieving a form 
layouts.
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ff827c89-6dd3-4016-9f99-9e3aa41f8855%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to restrict a class based view to one user group?

2014-11-06 Thread Daniel Grace
Thanks Bruno, I was decorating the 'post' method.  I've got it right now.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1b5fb39e-8590-415d-be89-40580ce7bc48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to restrict a class based view to one user group?

2014-11-06 Thread Daniel Grace
I solved this using a "method_decorator" and "user_passes_test".

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


How to restrict a class based view to one user group?

2014-11-05 Thread Daniel Grace
Hi,
Say I have a function as follows:

def is_supervisor(user):
return user.groups.filter(name='supervisor').exists()

...and a CBV for deleting records:

class DeleteFlow(DeleteView):
# etc...

How can I restrict access to this view using the function?
I understand that this may be possible with a mixin, but how?
Or is there a better way?

Thanks

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


Re: How to handle exceptions in RequestContext?

2014-11-05 Thread Daniel Grace
I see where you are coming from Carl, thanks for the information.  Do you 
have a suitable example of where one might put error handling in the view 
code?

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


How to handle exceptions if RequestContext fails?

2014-11-03 Thread Daniel Grace
Say I have the following code:

logger = logging.getLogger(__name__)

def render_error(scr_msg, err_msg, context):
logger.debug(err_msg)
return render_to_response('error.html', {'message': scr_msg}, context)
...
def some_view():
try:
   context = RequestContext(request)
...
except Exception as e:
return render_error('An error occured whilst showing some view.', 
e.args[0], context)

... then how do I handle the exception without a context?  Should I use the 
render function instead of render_to_response in the exception handler?

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


Re: How to generally handle exceptions in function based and class based views?

2014-11-03 Thread Daniel Grace
Thanks for the information Aliane and Steven, although I still don't know 
what to do when handling exceptions in say form_valid of a CBV.  How to 
render the error in this case?

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


How to handle exceptions in RequestContext?

2014-11-03 Thread Daniel Grace
Say I have the following code:

try:
context_dict = {}
context = RequestContext(request)
...
except Exception as e:
return render_to_response('error.html', context_dict, context)

...then how do I handle the exception without a context?  Should I use the 
render function instead of render_to_response in the exception handler?

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


Re: How to generally handle exceptions in function based and class based views?

2014-11-03 Thread Daniel Grace
OK, say if I have a function based view then how do I handle the exception?

try:
context = RequestContext(request)
context_dict = {}
...
return render_to_response('my_file.html', context_dict, context)
except Exception as e:
# what to do here?

What about class based views (in form_valid etc)?

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


How to generally handle exceptions in function based and class based views?

2014-11-02 Thread Daniel Grace
Hi, I'm looking for some information / examples of how to generally handle 
exceptions and show a message to the user, in function based and class 
based views.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3dc3d203-a2a1-476e-a06b-75a5f8d06d2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Calling a function for a url tag parameter

2014-10-30 Thread Daniel Grace
Hi,
I am trying to use the url tag on some parameters, one of which needs to 
come from a function.
For example as follows:
{% with state_url=encode_url flow.state.description %}
advance

encode_url is defined as follows:
@register.simple_tag
def encode_url(link_text):
return link_text.replace(' ', '_')

This causes an error on the with statement:
Request Method: GET
Request URL: http://127.0.0.1:8000/list_flows/
Django Version: 1.7
Exception Type: TemplateSyntaxError
Exception Value: 
'with' received an invalid token: 'flow.state.description'

I'm guessing that you cannot put another template tag in the "with" 
statement.  I cannot see a way around this.  Any ideas?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9a93cbaf-0f47-41d5-9eea-e6d3297caeac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


What is the purpose of the include function?

2014-10-28 Thread Daniel Grace
Hi,
In reference to urls.py what is the purpose of the include function?  For 
example what is the difference between these two lines?
url(r'^admin/', admin.site.urls),
url(r'^admin/', include(admin.site.urls)),


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2bb2e4d6-43e5-4615-81ed-e5103bb27ca7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to get rid of help text on a ModelForm?

2014-10-28 Thread Daniel Grace
Oops, too much indentation on the "def ..." line.

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


How to get rid of help text on a ModelForm?

2014-10-27 Thread Daniel Grace
Hi,
I have a ModelForm for creating users, but it shows some help text 
"Required. 30 characters..." next to the username field.
How do I get rid of this text?  I tried the following, but the text remains 
on the form:

class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput())
class Meta:
model = User
fields = ['username', 'email', 'password']
def __init__(self, *args, **kwargs):
super(UserForm, self).__init__(*args, **kwargs)
for fieldname in self.fields:
self.fields[fieldname].help_text = None

Any ideas?
Thanks

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


Re: How to get related data on one to one field of a foreign key?

2014-10-25 Thread Daniel Grace
I just used the following:
{{ log.user.userprofile.picture }}
... and I didn't need the select_related.

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


How to get related data on one to one field of a foreign key?

2014-10-25 Thread Daniel Grace
Hi,
I have a log table with a foreign key to the user table, and a userprofile 
table with a one to one field to the user table:

class Log(models.Model):
user = models.ForeignKey(User)
...

class UserProfile(models.Model):
user = models.OneToOneField(User)
picture = models.ImageField(upload_to='profile_images', blank=True)
... 

In my ListView I want to get the user profile for each log.  I know I can 
use select_related to get the related users of the log as follows:
queryset = Log.objects.select_related('user').order_by('created')

... but how do I get the related profiles and pass these on to the 
template, so I can for example display the picture for each log?

Thanks

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


Re: Problem with Pillow image resize and save

2014-10-25 Thread Daniel Grace
I need to include the following steps, but I don't know how:
1. copy the 'picture' file
2. resize it (the copy)
3. save it to the upload directory
4. store it in the 'thumb' field
... continue as before and save the 'profile'.

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


Problem with Pillow image resize and save

2014-10-24 Thread Daniel Grace
Hi,
I am trying to put together some code for resizing an image and storing the 
resized image on the database, but I am running into some problems having 
struggled to find some decent examples online.  Here is what I have come up 
with so far, in the model:

class UserProfile(models.Model):
user = models.OneToOneField(User)
website = models.URLField(blank=True)
picture = models.ImageField(upload_to='profile_images', blank=True)
thumb = models.ImageField(upload_to='profile_images', blank=True)

.. and in the view:

def register(request):
context = RequestContext(request)
registered = False
if request.method == 'POST':
user_form = UserForm(data=request.POST)
profile_form = UserProfileForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
if 'picture' in request.FILES:
profile.picture = request.FILES['picture']
thumb = Image.open(request.FILES['picture'])
profile.thumb = thumb.resize((200, 200), Image.ANTIALIAS)
profile.save()
registered = True
else:
print(user_form.errors, profile_form.errors)
else:
user_form = UserForm()
profile_form = UserProfileForm()
context_dict = {}
context_dict['user_form'] = user_form
context_dict['profile_form'] = profile_form
context_dict['registered'] = registered
return render_to_response('register.html', context_dict, context)

The error is as follows:
Request Method: POST
Request URL: http://127.0.0.1:8000/register/
Django Version: 1.7
Exception Type: AttributeError
Exception Value: 
_committed
Exception Location: C:\landy\lib\site-packages\PIL\Image.py in __getattr__, 
line 608

Any ideas?
Thanks

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


Re: Is there a way to supress blank lines in the HTML?

2014-10-24 Thread Daniel Grace
Thanks people for the info.  I was looking for a way to beautify the code, 
rather than for performance / compression.  In particular I came across 
this when I implemented a template tag which, under certain circumstances 
returns an empty string.  This works well but causes blank lines in the 
code, if they are present in the original template.  I did find the 
almostspaceless template tag on 
http://kuttler.eu/code/django-almost-spaceless-template-tag/ 
but I could not get it to work, as I don't know where "re.sub" comes from.

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


Is there a way to supress blank lines in the HTML?

2014-10-22 Thread Daniel Grace
Hi,
Is there a way to suppress blank lines in the HTML?
I tried using the spaceless tag but it is overkill for what I want.
I just want to suppress the blank lines from the HTML and not all space.

Any ideas?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/98887ff8-1b61-4618-af71-1c7c5c9a4b86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I display list of pages with a ListView object?

2014-10-22 Thread Daniel Grace
I found a solution by writing a custom template tag, passing in the current 
page and number of pages from page_obj.
Is that an acceptable solution or can this be done without a custom tag?

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


How do I display list of pages with a ListView object?

2014-10-22 Thread Daniel Grace
Hi,
How do I display list of pages with a ListView object?  For example display 
a link for each page (except maybe the current page):
previous 1 2 3 4 next

Currently I use the following in a view to display "previous" and "next":
{% if page_obj.has_previous %}
previous
{% endif %}
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
{% if page_obj.has_next %}
next
{% endif %}

I tried using a for loop with a template tag and a reference to page_obj, 
but I could not get it to work.  Any ideas?

Thanks

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


Re: Best way to display master detail data, with class based view or function based view?

2014-10-19 Thread Daniel Grace
I found the following thread at stackoverflow:
http://stackoverflow.com/questions/9777121/django-generic-views-when-to-use-listview-vs-detailview

I may want to paginate the list so it would seem to make sense to use the 
list view (for the events) and just display the flow fields at the top of 
the page.

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


Best way to display master detail data, with class based view or function based view?

2014-10-19 Thread Daniel Grace
I have implemented a model where one flow has many events as follows:
class Event(models.Model):
flow = models.ForeignKey(Flow)
...

I need a page to display one or two fields from a single flow and a list of 
all related events.
Should I implement this with a DetailView, a ListView (if either is 
possible) or just a plain function based view?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c2266570-1806-4778-99ec-666f87f11ec5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: NoReverseMatch error

2014-10-19 Thread Daniel Grace
You were right Vijay.  I worked this out.  I needed to set type and state 
via the context as follows:

def get_context_data(self, **kwargs):
context = super(TestFlow, self).get_context_data(**kwargs)
context.update({'type': self.kwargs['type'], 'state': 
self.kwargs['state']})
return context

... then reference type and state in the url template tag:


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ea14bda3-1e09-471f-bb2a-aacbc74e8b48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


NoReverseMatch error

2014-10-18 Thread Daniel Grace
Hi,
I get the following error on one of my view forms:
Request Method: GET
Request URL: http://127.0.0.1:8000/test/test_type_1/test_state_1/
Django Version: 1.7
Exception Type: NoReverseMatch
Exception Value: 
Reverse for 'create-flow-params' with arguments '()' and keyword arguments 
'{}' not found. 1 pattern(s) tried: 
['test/(?P\\w+)/(?P\\w+)/$']

The url for this view is as follows:
url(r'^test/(?P\w+)/(?P\w+)/$', 
login_required(views.TestFlow.as_view(success_url="/")), 
name='create-flow-params'),

The html line which the error refers to is as follows:


I'm doing something wrong.  Any ideas?

Thanks

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


Re: How to display BST (British Summer Time)?

2014-10-17 Thread Daniel Grace
I installed pytz and this problem went away.
Cheers

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


Re: How to display BST (British Summer Time)?

2014-10-17 Thread Daniel Grace
The date function can only display the offset, it does not actually add the 
offset to the date time.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0f7fbc5c-83a2-4a7d-86a1-705dad309bc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to display BST (British Summer Time)?

2014-10-17 Thread Daniel Grace
Hi,
I have the time zone set as follows:
TIME_ZONE='Europe/London'
USE_TZ = True

This is the same as GMT.  But what I want is BST (British Summer Time) for 
display purposes, which is UTC + 1 for the "summer" and UTC for the rest of 
the year.

How do I convert to this the value in my templates?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3437a26b-5332-440d-88a8-f98ffb500122%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with a token in my custom template tag

2014-10-15 Thread Daniel Grace
I got it working thanks.  My template tag file is as follows:

from django import template
from django.utils import timezone
register = template.Library()

@register.simple_tag
def rowcolour(dt):
diff = timezone.now() - dt
if diff.days > 14:
return "pinkrow"
else:
return "greyrow"


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e7265a1a-6959-48b8-963e-5a73d420810f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problem with a token in my custom template tag

2014-10-15 Thread Daniel Grace
Hi,
I'm encountering the following problem with a token in my custom template 
tag:
Request Method: GET
Request URL: http://127.0.0.1:8000/flows/
Django Version: 1.7
Exception Type: ValueError
Exception Value: 
need more than 2 values to unpack
Exception Location: C:\landy\cresta\flow\templatetags\flow_extras.py in 
rowcolour, line 7

Here is the template file:
from django import template
from datetime import datetime, timedelta
register = template.Library()

@register.tag
def rowcolour(parser, token):
nm, dt, fmt = token.split_contents() # this is line 7
diff = datetime.now() - dt 
if diff.days > 14:
return "pinkrow"
else:
return "greyrow"

... here is the line in the html file:


... and "created" is defined as follows in the model:
created = models.DateTimeField(db_index=True, auto_now_add=True)

I'm trying to extract the datetime from the token.  Any ideas?

Thanks.

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


Re: What is the correct way to set a field value in the form_valid method of a CreateView?

2014-10-14 Thread Daniel Grace
I found the way to do this is with the "form.save" method, for example in 
the form_valid:
state = get_state("test type", "test state")
obj = form.save(commit=False)
obj.state = state
obj.save()

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


Re: Naive datetime / time zone warning

2014-10-13 Thread Daniel Grace
I used "auto_now_add=True" in the model and the warning went away.

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


Re: Naive datetime / time zone warning

2014-10-13 Thread Daniel Grace
I changed "datetime.now" to "timezone.now" and I get the exact same 
warning.  What is going on?

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


Naive datetime / time zone warning

2014-10-13 Thread Daniel Grace
Hi.
Here is my model:

class Flow(models.Model):
state = models.ForeignKey(State)
created = models.DateTimeField(default=datetime.now)
modified = models.DateTimeField(db_index=True, default=datetime.now)
def __str__(self):
return str(self.id)

I am getting warnings about time zone support such as the following:

C:\landy\lib\site-packages\django\db\models\fields\__init__.py:1278: 
RuntimeWarning: DateTimeField Flow.modified received a naive datetime 
(2014-10-13 17:31:17.510556) while time zone support is active. 
RuntimeWarning)

I have the following line in my settings file:
USE_TZ = True

Any ideas?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d904851e-d32a-454f-954a-c4887b1d97c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


What is the correct way to set a field value in the form_valid method of a CreateView?

2014-10-13 Thread Daniel Grace
Hi,
What is the correct way to set a field value in the form_valid method of a 
CreateView?  Note the field is not on the form and I don't want to use a 
default value in the model.
For example:

def get_state(type_desc, state_desc):
type = Type.objects.get(description=type_desc)
return State.objects.get(state_type=type, description=state_desc)

class CreateFlow(CreateView):
model = Flow
fields = []
template_name = 'create_flow.html'
def form_valid(self, form):
state = get_state("test type", "test state")
# How to set the state field here on the Flow table?
result = super(CreateFlow, self).form_valid(form) 
log = Log(user=self.request.user, flow=self.object, state=state)
log.save()
return result

This gives an error because the state field on the Flow table has not been 
given a value:
Request Method: POST
Request URL: http://127.0.0.1:8000/create/
Django Version: 1.7
Exception Type: IntegrityError
Exception Value: 
null value in column "state_id" violates not-null constraint

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c164b88a-1da1-449a-a409-c6a47aa58b4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem when getting the ID of the record just created

2014-10-13 Thread Daniel Grace
Thanks for the help.  I got the ID working and I used the 
"self.user.request".

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/29ecd10b-1f18-4d55-a37a-9704bf3795ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to get user ID and ID of newly created record in a CreateView?

2014-10-13 Thread Daniel Grace
I made a different approach after getting help, which I now have working:
https://groups.google.com/forum/#!topic/django-users/eYDfCEZ0eQQ

On Monday, 13 October 2014 14:45:09 UTC+1, Collin Anderson wrote:
>
> Hi Daniel,
>
> Interesting. Could you post a traceback?
>
> Thanks,
> Collin
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/126c540e-4c61-47ff-bc3c-7bfa47fb3506%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problem when getting the ID of the record just created

2014-10-13 Thread Daniel Grace
Hi,
I have problem when getting the ID of the record just created.

class CreateFlow(CreateView):
model = Flow
fields = ['state']
template_name = 'create_flow.html'
def form_valid(self, form):
user = User.objects.get(pk=self.request.user.id)
flow = Flow.objects.get(pk=self.kwargs['pk'])
log = Log(user=user, flow=flow, state=1)
log.save()
return super(CreateFlow, self).form_valid(form)

... gives the error:
Request Method: POST
Request URL: http://127.0.0.1:8000/create/
Django Version: 1.7
Exception Type: KeyError
Exception Value: 
'pk'
Exception Location: C:\landy\cresta\flow\views.py in form_valid, line 64
Python Executable: C:\landy\Scripts\python.exe
Python Version: 3.4.0
Python Path: 
['C:\\landy\\cresta',
 'C:\\Windows\\system32\\python34.zip',
 'C:\\Python34\\DLLs',
 'C:\\Python34\\lib',
 'C:\\Python34',
 'C:\\landy',
 'C:\\landy\\lib\\site-packages']
Server time: Mon, 13 Oct 2014 13:40:49 +0100

What is the correct way to get the ID of the record just created?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8aaceba9-0203-489a-a57f-09fa26ce163c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to get user ID and ID of newly created record in a CreateView?

2014-10-12 Thread Daniel Grace
I get the error:
'CreateFlow' object has no attribute 'user'

How do I get the id of the record just created?

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


How to get user ID and ID of newly created record in a CreateView?

2014-10-10 Thread Daniel Grace
Hi, I am using a CreateView.  I want to create some related data on a table 
("Log" model), so I need the ID of the record being created for the related 
field (see "flow" below).  Also I need the ID of the user creating the 
record.  Something like the following:

from django.utils import timezone
from django.views.generic.edit import CreateView
from django.contrib.auth.decorators import login_required
from flow.models import Flow, Log

class CreateFlow(CreateView):
model = Flow
fields = ['state']
template_name = 'create_flow.html'
# there is a problem with this:
@login_required
def form_valid(self, form):
form.instance.created_by = self.request.user
# ... and this:
log = Log(user=self.request.user.id, flow=id, state=1, 
created=timezone.now)
log.save()
return super(CreateFlow, self).form_valid(form)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9922a44a-b4ce-4fdd-9b4b-044507c3d1ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Python question about positioning of "from... import" statement

2014-10-01 Thread Daniel Grace
OK, I should have read the warning on the Tango with Django page section 
5.8:

"When importing Django models, make sure you have imported your project’s 
settings by that stage. If you don’t, an exception will be raised. This is 
why we import Category and Page towards the end of the population script, 
rather than at the top."

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/64b80a37-cd4c-458b-84a8-17cd3ea891fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Python question about positioning of "from... import" statement

2014-10-01 Thread Daniel Grace
Hi, this is more of a Python question but here is something I don't 
understand in a Django script.
The following script works fine:

import os
import django

if __name__ == '__main__':
print("Starting Rango delete data script...")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tango.settings')
django.setup()
from rango.models import Category, Page
Page.objects.all().delete()
Category.objects.all().delete()
print("Deleted all data from tables: Page and Category.")

...but when I move the "from... import" statement to the top of the file:

import os
import django
from rango.models import Category, Page

if __name__ == '__main__':
print("Starting Rango delete data script...")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tango.settings')
django.setup()
Page.objects.all().delete()
Category.objects.all().delete()
print("Deleted all data from tables: Page and Category.")

...I get an error:

  File "C:\landy\lib\site-packages\django\conf\__init__.py", line 40, in 
_setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting 
DEFAULT_INDEX_TAB
LESPACE, but settings are not configured. You must either define the 
environment
 variable DJANGO_SETTINGS_MODULE or call settings.configure() before 
accessing s
ettings.

What is going on?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/955fb638-1724-4115-951a-668218e68771%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with populate script

2014-10-01 Thread Daniel Grace
I got this working, I had to do two things.
1. add the following line at the top of the script:
import django
2. add the following line after "os.environ.setdefault...":
django.setup()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/758faacb-94c9-41cb-953e-6ed4a7e8f9c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problem with populate script

2014-09-29 Thread Daniel Grace
I am trying to follow the tutorial at http://www.tangowithdjango.com/
I am stuck in section 5.8 where it shows how to create a script to populate 
the database.
I created a script called "populate.py" as shown (except I added brackets 
for the Python 3 print statements),
and saved it in the root directory for my project.
But when I run the script I get an error:

(landy) C:\landy\tango>populate.py
Starting Rango population script...
Traceback (most recent call last):
  File "C:\landy\tango\populate.py", line 59, in 
from rango.models import Category, Page
  File "C:\landy\tango\rango\models.py", line 1, in 
from django.db import models
ImportError: No module named 'django.db'

I tried placing the script in C:\landy\tango\tango and C:\landy\tango\rango 
directories but I get similar errors.

Is it a better approach to make the populate script into a manage command?
Or should I be using fixtures?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a05392f4-bf88-403d-98da-8478595be570%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems with psycopg2 on Windows 7 64 bit

2014-09-27 Thread Daniel Grace
I got around this particular problem.  The Windows installer for psycopg 
(at http://www.stickpeople.com/projects/python/win-psycopg/ 
)
 
installs for the global instance of Python,
not the virtualenv.  I copied the psycopg folder and the "egg-info" file to 
the virtualenv and the "No module named..." error disappeared.

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


Problems with psycopg2 on Windows 7 64 bit

2014-09-27 Thread Daniel Grace
I have installed Python 3.4, Django 1.7, Postgresql 9.3 and psycopg2-2.5.4 
(using the Windows installer 
at http://www.stickpeople.com/projects/python/win-psycopg/)

When I try a syncdb command from my virtualenv I get the following error:

(landy) C:\landy\cresta>python manage.py syncdb
Traceback (most recent call last):
  File 
"C:\landy\lib\site-packages\django\db\backends\postgresql_psycopg2\base.p
y", line 23, in 
import psycopg2 as Database
ImportError: No module named 'psycopg2'

I am not sure if I needed to do:
> pip install psycopg2

...which gives the following:

error: Unable to find vcvarsall.bat

I have Visual Studio 2012 installed if that helps?  Any other ideas?

Thanks.

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


Re: Error installing psycopg2-2.5.4 on Windows 7

2014-09-27 Thread Daniel Grace
I solved this.  I was using the wrong version of psycopg2, I needed the 64 
bit version.

On Saturday, 27 September 2014 14:35:43 UTC+1, Daniel Grace wrote:
>
> Hi,
> I have Python 3.4, Django 1.7 and Postgresql 9.3 installed.  I get the 
> following error when installing pscyopg2-2.5.4 on Windows 7:
>
> Python version 3.4 required, which was not found in the registry.
>
> Any ideas?
>
> Thanks.
>

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


Error installing psycopg2-2.5.4 on Windows 7

2014-09-27 Thread Daniel Grace
Hi,
I have Python 3.4, Django 1.7 and Postgresql 9.3 installed.  I get the 
following error when installing pscyopg2-2.5.4 on Windows 7:

Python version 3.4 required, which was not found in the registry.

Any ideas?

Thanks.

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


Re: syncdb error with Mysql database on Windows 7

2014-09-27 Thread Daniel Grace
For the record I solved this, I was mistaken there was no "mydb" schema in 
MySQL.  I created this schema and ran the "syncdb" command without any 
problems.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/88715e60-0ed6-443b-b23e-5a2767cf92d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


syncdb error with Mysql database on Windows 7

2014-09-24 Thread Daniel Grace
I have a virtualenv with Python 3.4, Django 1.7 and MySQL installed on 
Windows 7.
I also have  the MySQL / Python adapter installed and the database settings 
in settings.py:

DATABASES = {
'default': {
'NAME': 'mydb',
'ENGINE': 'mysql.connector.django',
'USER': 'root',
'PASSWORD': 'fishy1777',
}
}

When I do a syncdb I get the following errors:

(landy) C:\landy\cresta>python manage.py syncdb
Traceback (most recent call last):
  File "C:\landy\lib\site-packages\django\db\backends\__init__.py", line 
133, in
 ensure_connection
self.connect()
  File "C:\landy\lib\site-packages\django\db\backends\__init__.py", line 
122, in
 connect
self.connection = self.get_new_connection(conn_params)
  File "C:\landy\lib\site-packages\mysql\connector\django\base.py", line 
590, in
 get_new_connection
cnx = mysql.connector.connect(**conn_params)
  File "C:\landy\lib\site-packages\mysql\connector\__init__.py", line 157, 
in co
nnect
return MySQLConnection(*args, **kwargs)
  File "C:\landy\lib\site-packages\mysql\connector\connection.py", line 
122, in
__init__
self.connect(**kwargs)
  File "C:\landy\lib\site-packages\mysql\connector\connection.py", line 
431, in
connect
self._open_connection()
  File "C:\landy\lib\site-packages\mysql\connector\connection.py", line 
398, in
_open_connection
self._ssl)
  File "C:\landy\lib\site-packages\mysql\connector\connection.py", line 
187, in
_do_auth
self._auth_switch_request(username, password)
  File "C:\landy\lib\site-packages\mysql\connector\connection.py", line 
224, in
_auth_switch_request
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1049 (42000): Unknown database 
'mydb'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File "C:\landy\lib\site-packages\django\core\management\__init__.py", 
line 385
, in execute_from_command_line
utility.execute()
  File "C:\landy\lib\site-packages\django\core\management\__init__.py", 
line 354
, in execute
django.setup()
  File "C:\landy\lib\site-packages\django\__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
  File "C:\landy\lib\site-packages\django\apps\registry.py", line 108, in 
popula
te
app_config.import_models(all_models)
  File "C:\landy\lib\site-packages\django\apps\config.py", line 197, in 
import_m
odels
self.models_module = import_module(models_module_name)
  File "C:\Python34\lib\importlib\__init__.py", line 104, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 2231, in _gcd_import
  File "", line 2214, in _find_and_load
  File "", line 2203, in 
_find_and_load_unlocked
  File "", line 1200, in _load_unlocked
  File "", line 1129, in _exec
  File "", line 1448, in exec_module
  File "", line 321, in 
_call_with_frames_removed
  File "C:\landy\lib\site-packages\django\contrib\auth\models.py", line 40, 
in <
module>
class Permission(models.Model):
  File "C:\landy\lib\site-packages\django\db\models\base.py", line 125, in 
__new
__
new_class.add_to_class('_meta', Options(meta, **kwargs))
  File "C:\landy\lib\site-packages\django\db\models\base.py", line 300, in 
add_t
o_class
value.contribute_to_class(cls, name)
  File "C:\landy\lib\site-packages\django\db\models\options.py", line 166, 
in co
ntribute_to_class
self.db_table = truncate_name(self.db_table, 
connection.ops.max_name_length(
))
  File "C:\landy\lib\site-packages\django\db\__init__.py", line 40, in 
__getattr
__
return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "C:\landy\lib\site-packages\django\db\utils.py", line 243, in 
__getitem__

conn = backend.DatabaseWrapper(db, alias)
  File "C:\landy\lib\site-packages\mysql\connector\django\base.py", line 
534, in
 __init__
self.ensure_connection()
  File "C:\landy\lib\site-packages\django\db\backends\__init__.py", line 
133, in
 ensure_connection
self.connect()
  File "C:\landy\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\landy\lib\site-packages\django\utils\six.py", line 549, in 
reraise
raise value.with_traceback(tb)
  File "C:\landy\lib\site-packages\django\db\backends\__init__.py", line 
133, in
 ensure_connection
self.connect()
  File "C:\landy\lib\site-packages\django\db\backends\__init__.py", line 
122, in
 connect
self.connection = self.get_new_connection(conn_params)
  File "C:\landy\lib\site-packages\mysql\connector\django\base.py", line 
590, in
 get_new_connection
cnx = mysql.connector.connect(**conn_params)
  File "C:\landy\lib\site-packages\mysql\connector\__init__.py", line 157, 
in co
nnect
return MySQLConnection(*args, **kwargs)
  File "C:\landy\lib\site-packages\mysql\connector\connection.py", line 
122, in
__init__
self.connect(**kwargs)
  File "

Re: How to set block variable in view code?

2014-09-14 Thread Daniel Grace
Thanks for the info.  I am beginning to see the power of these 
substitutions.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b4c7135b-92e1-474e-a780-573a460a6f04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to set block variable in view code?

2014-08-18 Thread Daniel Grace
I am struggling to understand block tags.  I have two block tags in my HTML 
template as follows:


{% block side_hdr %}{% endblock%}

{% block content %}{% endblock %}

How (if possible) do I set these tags in my class based view?

class TestView(TemplateView):
template_name = "base.html"

Thanks.

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


How to set block variable in view code?

2014-08-18 Thread Daniel Grace
I am struggling to understand block variables.  I have two block variables 
in my HTML template as follows:


{% block side_hdr %}{% endblock%}

{% block content %}{% endblock %}

How (if possible) do I set these variables in my class based view?

class TestView(TemplateView):
template_name = "base.html"

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/43795e2f-1f53-4df7-ba5f-79477ccd2f08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Cannot import in admin.py

2014-08-14 Thread Daniel Grace
I get an error after editing my admin.py file as follows:

from django.contrib import admin
from flow.models import Flow
admin.site.register(Flow)

... here is the error:
ImportError at /
cannot import name 'Flow'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.6.5
Exception Type: ImportError
Exception Value: 
cannot import name 'Flow'
Exception Location: C:\landy\cresta\flow\admin.py in , line 2
Python Executable: C:\landy\Scripts\python.exe
Python Version: 3.4.0
Python Path: 
['C:\\landy\\cresta',
 'C:\\Windows\\system32\\python34.zip',
 'C:\\Python34\\DLLs',
 'C:\\Python34\\lib',
 'C:\\Python34',
 'C:\\landy',
 'C:\\landy\\lib\\site-packages']
Server time: Thu, 14 Aug 2014 18:55:00 +0100

I am running in a virtual env.

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


I can't load fixtures

2014-08-14 Thread Daniel Grace
I created a fixtures file called testdata.xml in a fixtures folder, but I 
can't load the fixtures file into the database.

I placed an __init__.py file in the fixtures folder (not sure about this 
step, is it needed?)

I put the fixtures directory in settings.py:
FIXTURE_DIRS = (
   '/myapp/fixtures/',
)

I tried two ways to load the fixture, but neither worked:
>python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
>python manage.py loaddata "myapp/fixtures/testdata.xml"
C:\myenv\lib\site-packages\django\core\management\commands\loaddata.py:216: 
User
Warning: No fixture named 'myapp/fixtures/testdata' found.
  warnings.warn("No fixture named '%s' found." % fixture_name)
Installed 0 object(s) from 0 fixture(s)

Any ideas?
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/92c480fa-66ba-4554-888d-27bbd6fb958d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to disable application / project?

2014-08-14 Thread Daniel Grace
I have two projects "djangotest" (from the django tutorial) and "cresta".
When I start the server with the "runserver" command in the cresta 
directory and go to
http://127.0.0.1:8000/admin/
... I see "Polls Tutorial".  I can't login with any users from the cresta 
database.
How do I disable the Polls tutorial and just use the cresta project and its 
applications?
Why is "Polls Tutorial" even appearing when I am running the server through 
the cresta directory?

Thanks


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


Re: How to run Python script? (configure settings error)

2014-08-13 Thread Daniel Grace
I used this method and got my script working OK.

On Wednesday, 13 August 2014 15:37:30 UTC+1, Andrew Farrell wrote:
>
> Note: this is much better documented at 
> https://docs.djangoproject.com/en/dev/howto/custom-management-commands/
>
> You want to move this file to the management.commands module. I don't know 
> what the equivalent commands are on windows, but on linux this would be.
> 1) `cd myapp; mkdir management`: Within you app, in the same directory as 
> views.py create a directory called 'management'
> 2) `cd management`: Go into that directory
> 3) `touch__init__.py`: create an empty file named __init__.py
> 4) `mkdir commands`: create a directory named "commands"
> 5) `cd commands`: go into that directory
> 6) `touch __init__.py`: create another empty file named__init.py
> 7) `echo 'from django.conf import settings' > mycommandname.py`: create a 
> file named with the command you want within that directory.
> 8) You need to have something in that file that looks like:
>
> from django.core.management.base import BaseCommand
> class Command(BaseCommand):
> args = 'spam eggs'
> help = 'makes an omelette to throw at a silly English knigget'
> def handle(self, *args, **swargs):
> print settings.STATIC_ROOT
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/77fa1182-7ee1-48ef-bbe3-7b7235087307%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to run Python script? (configure settings error)

2014-08-13 Thread Daniel Grace
I have a Python script as follows:

from django.db import transaction
from django.contrib.auth.models import User
from flow.models import States, Types, Docs, Logs

if __name__ == '__main__':
with transaction.atomic():
models.Logs.objects.all().delete()
models.Docs.objects.all().delete()
models.States.objects.all().delete()
models.Types.objects.all().delete()
models.User.objects.all().delete()
user1 = User.objects.create_user('john', 'xxx...@gmail.com', 
'johnpass')
user1.save()

When I run this in IDLE I get the following error:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 38, in 
_setup
settings_module = os.environ[ENVIRONMENT_VARIABLE]
  File "C:\Python34\lib\os.py", line 651, in __getitem__
raise KeyError(key) from None
KeyError: 'DJANGO_SETTINGS_MODULE'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Daniel\Documents\Python\cresta\flow\test_data.py", line 7, 
in 
from django.contrib.auth.models import User
  File "C:\Python34\lib\site-packages\django\contrib\auth\__init__.py", 
line 6, in 
from django.middleware.csrf import rotate_token
  File "C:\Python34\lib\site-packages\django\middleware\csrf.py", line 14, 
in 
from django.utils.cache import patch_vary_headers
  File "C:\Python34\lib\site-packages\django\utils\cache.py", line 26, in 

from django.core.cache import get_cache
  File "C:\Python34\lib\site-packages\django\core\cache\__init__.py", line 
69, in 
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
  File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 54, in 
__getattr__
self._setup(name)
  File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 47, in 
_setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but 
settings are not configured. You must either define the environment 
variable DJANGO_SETTINGS_MODULE or call settings.configure() before 
accessing settings.

How do I configure these settings?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9b3a4974-26fd-4229-a3bf-7d7ce28dbdfe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Error in shell when following Django tutorial

2014-08-09 Thread Daniel Grace
I get an error in the shell when following the tutorial
https://docs.djangoproject.com/en/1.6/intro/tutorial01/

C:\Users\Daniel\My Documents\Python\DjangoTest\mysite>python manage.py shell
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 
bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from polls.model import Poll, Choice
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named 'polls.model'

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


Error in shell when following Django tutorial

2014-08-09 Thread Daniel Grace
I get an error in the shell when following the tutorial
https://docs.djangoproject.com/en/1.6/intro/tutorial01/

C:\Users\Daniel\My Documents\Python\DjangoTest\mysite>python manage.py shell
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 
bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from polls.model import Poll, Choice
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named 'polls.model'
>>> from polls.model import Poll, Choice

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


Not getting create table statements as described in the tutorial

2014-08-09 Thread Daniel Grace
I am following the tutorial 
at https://docs.djangoproject.com/en/1.6/intro/tutorial01/
I typed in the command: python manage.py sql polls
but there were no messages, and I did not get the create statements that 
are mentioned in the tutorial.
I'm not sure what is going on.

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