Monday, March 2, 2015

Can't run django!

Hi there,

I am using python 2.7 and django 1.75; when I run "manage.py runserver" I get the following error:

CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.
An exception has occurred, use %tb to see the full traceback.


My DEBUG is True.

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+unsubscribe@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/ea41d3e8-4d93-4076-8df8-a099360d13aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Custom lookup field for text comparison in Django 1.6

Hello,

I'm trying to emulate a non-spaces-all-lower text comparison filter in Django 1.6.x. In other words, I want the equivalent to this query

select * from myapp_mymodel where replace(lower(str), " ", "") = '<user_entry>'

Being my model something like this

from django.db import models    class MyModel(models.Model):      num = models.IntegerField()      str = models.CharField(max_length=16)

In my mind, this can be implemented with a custom lookup like this:

MyModel.objects.filter(str__customcomparison='spaces and UPPERCASE will not be taken into account')

I know Django 1.7 allows custom lookups creation, but can't make Django 1.6 work like this. I've tried implementing a custom QuerySet and a custom Manager for MyModel. In the custom QuerySet, I override the method _filter_or_exclude. 

Am I in the right path? Any suggestion?

Many thanks in advance

--
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+unsubscribe@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/041d82a9-531d-4817-a66d-5326f7996d1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Django(1.7) admin - separate user-profile section

Hi all,

I need to make a `passwordless` token system, and want to have a "Home › Passwordless › User tokens" in the Admin section. For the "User tokens" `list_display` I need all the "Users". (I do _not_ want to display the token information on the regular "User"-admin as just an extended "profile".) 

Any ideas on how to go about doing this?

So far I have this skeleton in `passwordless/model.py`, but I probably need some magic in `passwordless/admin.py` to list all the users with links to a custom token-manager form with custom widgets (create-token button, delete token button etc)...

from django.db import models
import jwt

class UserTokens(models.Model):
   
class Meta:
        verbose_name
= "User tokens"
        verbose_name_plural
= "User tokens"

    user
= models.OneToOneField(User)


class TokenBase(models.Model):
   
class Meta:
       
abstract = True

    token
= models.CharField(max_length=1000)    
    created_ts
= models.DateTimeField('Date created')
    expires_ts
= models.DateTimeField('Date expired')

   
def __str__(self):
       
return self.user.email


class AuthenticateToken(TokenBase):
    manager
= models.OneToOneField(UserTokens)

   
def validate(self, token):
       
pass    


class AuthorizeToken(TokenBase):  
    manager
= models.ForeignKey(UserTokens)
    revoked_ts
= models.DateTimeField('Date revoked')

   
def validate(self, token):
       
pass  


--
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+unsubscribe@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/a5bd42c5-bb3d-4a84-a50d-2d24fb5b0261%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Django 1.7 tutorial part 4, url

I ran into the following problem with the tutorial.

When I'm at http://127.0.0.1:8000/polls/1/, I get the expected page:


What's up?

 
 


However when I try to vote I get the error 

Page not found (404)

Request Method:POST
Request URL:http://127.0.0.1:8000/polls/1/vote/

No Question matches the given query.

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.


After some time I found that something is wrong with the urls. My polls/urls.py file was:

-----------------
from django.conf.urls import patterns, url

from polls import views

urlpatterns = patterns('',
    # ex: /polls/
    url(r'^$', views.index, name='index'),
    # ex: /polls/5/
    url(r'^(?P<question_id>\d+)/$', views.detail, name='detail'),

    url(r'^(?P<begins_with>\S+)/$', views.search, name='search'),
    # ex: /polls/5/results/
    url(r'^(?P<question_id>\d+)/results/$', views.results, name='results'),
    # ex: /polls/5/vote/
    url(r'^(?P<question_id>\d+)/vote/$', views.vote, name='vote'),
)
------------------

If I remove the "/" after "vote", then everything works. I had the same error when attempting to view the results, so I also
removed the "/" after results. My urls.py now looks like

    ...
    # ex: /polls/5/results
    url(r'^(?P<question_id>\d+)/results$', views.results, name='results'),
    # ex: /polls/5/vote
    url(r'^(?P<question_id>\d+)/vote$', views.vote, name='vote'),
   ...

Can someone explain me what is going on? thanks.

Note that the file mysite/urls.py is:

----------
from django.conf.urls import patterns, url

from polls import views

urlpatterns = patterns('',
    # ex: /polls/
    url(r'^$', views.index, name='index'),
    # ex: /polls/5/
    url(r'^(?P<question_id>\d+)/$', views.detail, name='detail'),

    url(r'^(?P<begins_with>\S+)/$', views.search, name='search'),
    # ex: /polls/5/results
    url(r'^(?P<question_id>\d+)/results$', views.results, name='results'),
    # ex: /polls/5/vote
    url(r'^(?P<question_id>\d+)/vote$', views.vote, name='vote'),
)
--------

--
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+unsubscribe@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/9f7a2a12-0e14-48a6-a70a-358deb5f7899%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Populating Django app db with JSON data

"custom Python code in a historical context"
FMPOV, it means that your code will be run exactly at a certain
schema of your DB. If your migration is the 3rd one, it will
always be run after your first two migrations, thus you will
know exactly your schema.

The schema is passed to your function (as apps and schema_editor)
in order to get your Model class.

Sorry if my explanation wasn't clear, hope it will help at least.

On 03/02/2015 10:27 AM, Murthy Sandeep wrote:
> Hi
>
> thanks for the info.
>
> The docs also say that RunPython runs "custom Python code
> in a historical context". What does that mean exactly? It seems
> related to the apps and schema_editor arguments passed to
> the custom method that will be called by RunPython - is this something
> like a snapshot of the app model that is stored when I do `python manage.py migrate`?
>
> Sandeep
>
>
>> On 2 Mar 2015, at 19:37, aRkadeFR <contact@arkade.info> wrote:
>>
>> Hello,
>>
>> Indeed, the data migration is the best way. Check out
>> the documentation here:
>> https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunPython
>>
>> You write your function that will be called by the RunPython
>> and will load your JSON.
>> Migration are ordered, your first migration will create the
>> tables and the second (your data migration) will load your
>> JSON.
>>
>> To create an empty migration:
>> ./manage.py makemigrations <app> --empty
>>
>> You can rename to a useful descriptive name the migration
>> file.
>>
>> Have a good one
>>
>>
>> On 03/02/2015 08:16 AM, Sandeep Murthy wrote:
>>> Hi
>>>
>>> I've tried to get the answer to this question (which is a bit open-ended) on stackoverflow without much success, which
>>> is basically this: what is the recommended approach to populating a pre-existing Django app database table (generated
>>> from a model and which is currently empty) with JSON data?
>>>
>>> There seem to be several alternatives given in the Django documentation (Django 1.7 manual) which include (1) fixtures,
>>> (2) SQL scripts, (3) data migrations. Of these I am a bit confused by the advice in the manual which suggests that (1)
>>> and (2) are only useful for loading initial data. That's not what I want to do. The data that the app needs is going to be
>>> persistent and permanent because the app is intended to be a web query tool for a large dataset that is currently in the
>>> form of several JSON files, each containing on average thousands of JSON objects, each object representing an entry
>>> corresponding to a table entry in a relational db. The data is not going to be re-loaded or change after entry, and there
>>> is no user facility for changing the data.
>>>
>>> The table has been created using the makemigrations and migrate tools, but is empty. I just need to populate the
>>> table with the JSON data. It seems that I need to write a custom data migration script that will insert the data into the
>>> table via the interpreter, and then I need to run python manage.py migrate. Is this the case, and if so, are there
>>> are examples that I could use?
>>>
>>> Thanks in advance for any suggestions.
>>>
>>> SM
>>> --
>>> 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+unsubscribe@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/db5919c5-ace4-4556-b90e-aa47baa26552%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/54F42164.6040505%40arkade.info.
>> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/54F43A59.60803%40arkade.info.
For more options, visit https://groups.google.com/d/optout.

Re: Melb Django School Second GO

Long time on and off list member. I went to the first round of classes
and would recommend. Very comfortable space, training leaders knew
their Django v well.

L.
------
"This is a profound psychological violence here. How can one even
begin to speak of dignity in labor when one secretly feels one's job
should not exist?"

On the Phenomenon of Bullshit Jobs, David Graeber
http://strikemag.org/bullshit-jobs/


On 2 March 2015 at 15:17, MelbDjango School <darren@acommoncreative.com> wrote:
> Hey Guys,
>
> Melb Django & Common Code is starting its second round of free classes on
> Django. The classes are going to be held fortnightly starting March 12 from
> 4-6pm. They will be going through the essentials of Django to advance
> topics. The course will be given by leading Django Developers in the
> industry. Please bring a laptop and we'll provide the rest. See you in
> School!
>
> If you have any questions please contact
> melbdjangoschool@acommoncreative.com.
>
> Cheers,
> Darren
>
> --
> 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+unsubscribe@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/b39acf36-3a9f-411d-8aff-a172c8bfa754%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/CAGBeqiPe7bSvKDNpOZ6Yu_dDbDmEpqM85vcyBQ%2BwgyD8Q9LcJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Populating Django app db with JSON data

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.26
Comment: GPGTools - https://gpgtools.org

iQIcBAEBCgAGBQJU9C0CAAoJEE/+9O67CIlEiEsQAIuFrB9kR6RKSi0GXzCXszcC
Mek7I/gF8gz7KkH3OhdhON5qIIv5awFMZoJ15Y80tAzex4kZmjjWtTW/x4nG5nI9
91JQPEcI938aMnXO9+jSX61Von6LWbvVrZJA9LwM/aq87xHD2UkmMr5LOhijTLNY
ISlEHOqaHq2OQ+0d7oh05LN//1rnrUpKjxhgVjHuThMBVhp3S1D+dKT7RsWD77t0
1EgmVPSmXH/bIgL0BgpqafJhSfMFPyRYKftx8mKK7uH6RWR52lMsc+69d4+ZnmMa
fEL3BBHSLiN24bHKFd699ou6DW+jr6TNVRno8uzpTDTJyFZBvI/7cUg+1t6etoEp
4l7rhUqslg86aG25PMDkAkMxyhdFAZyMZIKVOKAVyVUUoJTDTqSkfbAfoqjwbZIe
u+TtEnoL/TPbdOAzZJSL1bLAoCllqiWhRSPnzUznJ6k45HQVB8SW5z5wGD+HYkE8
GuaCm5PPwOJHIhDvat+GCLKX8xtzFVVjKSvilGXxgtZw+1nfj4jZ1XZCqejVtr7Q
OMWT/0MBmE+vsrG3b4UhFQJkf/cmtDk0lUxC+EudWxuRFBr/qrwg2x/dw1ZDVRmG
Z27bIrw5Za1J7wnyEAzESuBUvx4rPDGbnBn0zA+9KHb39SknyL2WDyG8joebc392
3ucZGdDa1jLxibWmZpDW
=BJ14
-----END PGP SIGNATURE-----
Hi

thanks for the info.

The docs also say that RunPython runs "custom Python code
in a historical context". What does that mean exactly? It seems
related to the apps and schema_editor arguments passed to
the custom method that will be called by RunPython - is this something
like a snapshot of the app model that is stored when I do `python manage.py migrate`?

Sandeep


> On 2 Mar 2015, at 19:37, aRkadeFR <contact@arkade.info> wrote:
>
> Hello,
>
> Indeed, the data migration is the best way. Check out
> the documentation here:
> https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunPython
>
> You write your function that will be called by the RunPython
> and will load your JSON.
> Migration are ordered, your first migration will create the
> tables and the second (your data migration) will load your
> JSON.
>
> To create an empty migration:
> ./manage.py makemigrations <app> --empty
>
> You can rename to a useful descriptive name the migration
> file.
>
> Have a good one
>
>
> On 03/02/2015 08:16 AM, Sandeep Murthy wrote:
>> Hi
>>
>> I've tried to get the answer to this question (which is a bit open-ended) on stackoverflow without much success, which
>> is basically this: what is the recommended approach to populating a pre-existing Django app database table (generated
>> from a model and which is currently empty) with JSON data?
>>
>> There seem to be several alternatives given in the Django documentation (Django 1.7 manual) which include (1) fixtures,
>> (2) SQL scripts, (3) data migrations. Of these I am a bit confused by the advice in the manual which suggests that (1)
>> and (2) are only useful for loading initial data. That's not what I want to do. The data that the app needs is going to be
>> persistent and permanent because the app is intended to be a web query tool for a large dataset that is currently in the
>> form of several JSON files, each containing on average thousands of JSON objects, each object representing an entry
>> corresponding to a table entry in a relational db. The data is not going to be re-loaded or change after entry, and there
>> is no user facility for changing the data.
>>
>> The table has been created using the makemigrations and migrate tools, but is empty. I just need to populate the
>> table with the JSON data. It seems that I need to write a custom data migration script that will insert the data into the
>> table via the interpreter, and then I need to run python manage.py migrate. Is this the case, and if so, are there
>> are examples that I could use?
>>
>> Thanks in advance for any suggestions.
>>
>> SM
>> --
>> 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+unsubscribe@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/db5919c5-ace4-4556-b90e-aa47baa26552%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/54F42164.6040505%40arkade.info.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/279E5DB5-57C9-4A85-9EDA-3A9159BE8925%40sandeepmurthy.is.
For more options, visit https://groups.google.com/d/optout.