Re: How to pass a string as url's parameter

2015-08-14 Thread James Schneider
You probably don't want to use the name directly, you should probably look
at creating a slug from the name and store it in a SlugField on your model.

https://docs.djangoproject.com/en/1.8/ref/models/fields/#slugfield
https://docs.djangoproject.com/en/1.8/ref/utils/#module-django.utils.text

Your URL regex already looks correct to capture a slug.

At that point it's just a matter of pulling the object via the slug in your
view:

fruit = get_object_or_404(Fruit, slug=fruit_name)

Of course that's assuming that your SlugField is named 'slug'. Make sure to
read up on slugs since they need to be unique, and generating them may be a
challenge.

-James
On Aug 13, 2015 12:18 PM, "I. Dié"  wrote:

> Hi evrybody,
>
> Here is my model:
>
> # fruits/models
> Class Fruit (models.Model):
> name =  models.CharField(max_length = 33,
>choices = NAME_CHOICES, default = MANGO)
># and so on...
>
> # fruits/views
> def fruit(request, fruit_name):
> fruit = get_object_or_404(Fruit)
> return render(request, 'fruits/fruit.html', {'fruit': fruit})
>
> # fruits/urls
> urlpatterns = [
> url(r'^$', views.index, name="index"),
> url(r'^(?P[-\w]+)/$', views.fruit, name='fruit'),
> ]
>
> When I used fruit_id, everything was ok.
> But I want to know how to use Fruit.name (a string) as url's parameter
> instead of fruit_id like this: myverybigmarket/fruits/mango better than
> myverybigmarket/fruits/1
>
> Ps: this is my first python/django project.
>
> 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/404e6ef5-99d7-4e38-8bf1-978b8690d733%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: How to pass a string as url's parameter

2015-08-14 Thread Snezhana Spasova
If I understand the question correct..

you can do 

fruit = get_object_or_404(Fruit, name=fruit_name) even if its not SlugField.

I dont recommend doing that with field that doesn't have unique=True 
because error will be raised if there are more than one objects with this 
name. 
(This equals Fruit.objects.get(name=fruit_name).)

On Thursday, August 13, 2015 at 10:18:38 PM UTC+3, I. Dié wrote:
>
> Hi evrybody,
>
> Here is my model:
>
> # fruits/models
> Class Fruit (models.Model):
> name =  models.CharField(max_length = 33,
>choices = NAME_CHOICES, default = MANGO)
># and so on...
>
> # fruits/views
> def fruit(request, fruit_name):
> fruit = get_object_or_404(Fruit)
> return render(request, 'fruits/fruit.html', {'fruit': fruit})
>
> # fruits/urls
> urlpatterns = [
> url(r'^$', views.index, name="index"),
> url(r'^(?P[-\w]+)/$', views.fruit, name='fruit'),
> ]
>
> When I used fruit_id, everything was ok. 
> But I want to know how to use Fruit.name (a string) as url's parameter 
> instead of fruit_id like this: myverybigmarket/fruits/mango better than 
> myverybigmarket/fruits/1
>
> Ps: this is my first python/django project.
>
> 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/ac426d9c-ea3b-4d8c-bd59-4f1b2fd5c7d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to pass a string as url's parameter

2015-08-14 Thread Snezhana Spasova
You can do 
  fruit = get_object_or_404(Fruit, name=fruit_name)

but i wont recommend doing this with field that is not unique because it 
basically resolves to Fruit.objects.get(name=fruit_name) which will raise 
error if there are two objects with the same name... Furthermore you have 
choices.. which means you have limited values to choose from.. Either 
change your field to unique=True and remove choices or don't use this 
method to get objects..
Hope I helped..

-Snejy

On Thursday, August 13, 2015 at 10:18:38 PM UTC+3, I. Dié wrote:
>
> Hi evrybody,
>
> Here is my model:
>
> # fruits/models
> Class Fruit (models.Model):
> name =  models.CharField(max_length = 33,
>choices = NAME_CHOICES, default = MANGO)
># and so on...
>
> # fruits/views
> def fruit(request, fruit_name):
> fruit = get_object_or_404(Fruit)
> return render(request, 'fruits/fruit.html', {'fruit': fruit})
>
> # fruits/urls
> urlpatterns = [
> url(r'^$', views.index, name="index"),
> url(r'^(?P[-\w]+)/$', views.fruit, name='fruit'),
> ]
>
> When I used fruit_id, everything was ok. 
> But I want to know how to use Fruit.name (a string) as url's parameter 
> instead of fruit_id like this: myverybigmarket/fruits/mango better than 
> myverybigmarket/fruits/1
>
> Ps: this is my first python/django project.
>
> 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/d7fbe2f8-2548-4134-8014-3433952ef375%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to pass a string as url's parameter

2015-08-14 Thread I . Dié

Thanks you all  Snejy and James.
Regards 


>

-- 
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/0a50fae7-d714-4a54-a533-8ac9eb74f6d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Community Blog not adding Posts from feed

2015-08-14 Thread Tim Graham
It was a bug on our end, please see 
https://code.djangoproject.com/ticket/25261 for resolution, and sorry for 
the inconvenience.

On Monday, August 10, 2015 at 10:38:28 AM UTC-4, Luciano Ferrari wrote:
>
> Hi everyone,
>
> Last week I added the RSS Feed to the Django Community Blog which was 
> approved by the Django Community.
>
> The problem is that I am not seeing any of the current posts of the feed 
> in the django community blog page.
>
> Does anyone have this issue before?
>
> Thanks,
> Luciano
>

-- 
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/62457dab-4549-4dfd-98ae-b284ea4d6183%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


AWS Ops Works - Setup DJango

2015-08-14 Thread Steve McAtee
Hello,

I'm a bit of a noob when it comes to DJango.  I am trying to deploy a 
zipped django application into AWS OpsWorks. 

I am using: https://github.com/alecpm/opsworks-web-python

I have built the stack and get it to start and install Django/python.

What I am stuck in is how do I take a Zip of a Django app and deploy it 
into AWS OpsWorks?  Normally in Java you would build an application. 
 However, I think this is wanting everything to be done in the Chef Recipe.

Any help would be appreciated.  I'd hate to have to go back to Java.



-- 
NOTICE: This electronic mail message and any files transmitted with it are 
intended exclusively for the individual or entity to which it is addressed. 
The message, together with any attachment, may contain confidential and/or 
privileged information. Any unauthorized review, use, printing, saving, 
copying, disclosure or distribution is strictly prohibited. If you have 
received this message in error, please immediately advise the sender by 
reply email and delete all copies.

-- 
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/eb7a36f5-b764-45b3-bc0b-671ff069f69f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Can u tell me how to build restful api project in django

2015-08-14 Thread HARSHIT GARG
I am getting the following error:

ImportError: rest_framework doesn't look like a module path

-- 
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/765ed0a8-f900-49cd-b4e1-ce8c91e75ac0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can u tell me how to build restful api project in django

2015-08-14 Thread Timothy W. Cook
Did you follow these instructions?
http://www.django-rest-framework.org/tutorial/quickstart/

Spend the time on the tutorial.  It will save you time in the long run.


On Fri, Aug 14, 2015 at 10:59 AM, HARSHIT GARG 
wrote:

> I am getting the following error:
>
> ImportError: rest_framework doesn't look like a module path
>
> --
> 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/765ed0a8-f900-49cd-b4e1-ce8c91e75ac0%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 


Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
MLHIM http://www.mlhim.org

-- 
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/CA%2B%3DOU3VZwt3_jhktVm2Df-L-XZ9Ut1Vqjx3L_oZxhvOGW4TkKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django: "Fake" multiple inheritance

2015-08-14 Thread michael
Hi all,

suppose I have the following model structure

from django.db import models

class Place(models.Model):
name = models.CharField(max_length=50)

class Restaurant(Place):
...

class Hotel(Place):
...

I already have a Restaurant in my database. This Restaurant is now also 
becoming a Hotel. I would like to declare this in the database as follows:

restaurant = Restaurant.objects.get(name='Will soon be a hotel')
Hotel.objects.create(pk=restaurant.pk)

Is this a safe thing to do?

Thanks,
Michael

-- 
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/a94e6a9a-919e-49ab-ac4c-e2e187a4f816%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can u tell me how to build restful api project in django

2015-08-14 Thread Rene Zelaya
I have found django-tastypie very useful to create a REST API: 
https://github.com/django-tastypie/django-tastypie

Here are the docs: 
http://django-tastypie.readthedocs.org/en/latest/index.html#quick-start

Best,
Rene

On Friday, August 14, 2015 at 10:22:40 AM UTC-4, HARSHIT GARG wrote:
>
> I am getting the following error:
>
> ImportError: rest_framework doesn't look like a module path
>

-- 
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/ec56e753-1431-482f-ad41-7ec6b293de52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Static version of a Django website ?

2015-08-14 Thread Stefano Probst
Hi,

i only know a generic way via HTTrack . If you 
want a copy of the rendered HTML.

-- 
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/1f00c270-cff0-4a2d-8662-4561baa9547c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django-tastypie checking of csrf token in requests

2015-08-14 Thread Rene Zelaya
Hi everyone,

We have a REST API built using django-tastypie, which most of our users 
access through our web application. However, we do have users that make 
requests to the API programmatically (using the python 'requests' library, 
for example) and use an OAuth token to do so (we have already set up our 
Tastypie API to do this OAuth authentication). 

How does Tastypie check for the csrf token, and does anybody have 
experience modifying the mechanism so that it does check it when users are 
in a session using the web application but does not require it if users are 
accessing programmatically AND have a valid OAuth token?

Thank you!

Rene

-- 
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/a2bfde34-18e9-4df0-b50c-cfaea48b1d5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to use the sites framework?

2015-08-14 Thread Avraham Serour
This would be one site with 3 routes, just create 3 views and 3 entries on
URLs.py, you don't need the sites framework

On Thu, Aug 13, 2015, 11:49 PM derek riemer 
wrote:

> Hi,
> I have 3 apps. A base site, with a main menu, a personal website with a
> biography, and a weather app. I was curious if the sites framework can
> distinguish each app as a separate site while they are all on the same
> domain? I have derekriemer.pythonanywhere.com, and on the apps are
> pointed to by / /weather and /personal under that domain. What would be
> the use case for me to use the sites framework?
> 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/55CD02B7.3000604%40gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop 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/CAFWa6tKW86mPWF8%3DmyvpTGP31a0zNOahZn3YypUGuiLTFaTY5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Instantiating the SQL implementation of Aggregates in Django 1.8

2015-08-14 Thread Ramana Subramanyam
 

I've been working on updating the existing code base that was using Django 
1.6 to Django 1.8. In the process, I've been facing a particular problem 
with aggregates. In this code, *PGDAggregate* class has a method 
*add_to_query* which is intended to instantiate the SQL implementation of 
the aggregate and sets it as a class variable (*aggregate*) which i'd be 
using to call the *as_sql* method in Default SQL 
Aggregate(django/db.models.sql.aggregates.Aggregate) from another file. 

My code (The first file, how I implement aggregate): 

from django.db.models.aggregates import Aggregate from 
django.db.models.sql.aggregates import Aggregate as SQLAggregate class 
PGDAggregate(Aggregate): """ Modified to allow Aggregate functions outside of 
the Django module """ def add_to_query(self, query, alias, col, source, 
is_summary): """Add the aggregate to the nominated query. This method is used 
to convert the generic Aggregate definition into a backend-specific definition. 
* query is the backend-specific query instance to which the aggregate is to be 
added. * col is a column reference describing the subject field of the 
aggregate. It can be an alias, or a tuple describing a table and column name. * 
source is the underlying field or aggregate definition for the column 
reference. If the aggregate is not an ordinal or computed type, this reference 
is used to determine the coerced output type of the aggregate. * is_summary is 
a boolean that is set True if the aggregate is a summary value rather than an 
annotation. """ klass = globals()['%sSQL' % self.name] aggregate = klass(col, 
source=source, is_summary=is_summary, **self.extra) # Validate that the backend 
has a fully supported, correct # implementation of this aggregate 
query.aggregates[alias] = aggregate self.aggregate = aggregate class 
BinSort(PGDAggregate): alias = 'BinSort' name = 'BinSort' class 
BinSortSQL(SQLAggregate): sql_function = '' sql_template = 
'%(function)sFLOOR((IF(%(field)s<%(offset).16f,360,0)+%(field)s-%(offset).16f)/%(bincount).16f)-IF(%(field)s=%(max).16f,1,0)'

This is how I'm trying to use the aggregate attribute(an instance of 
Default SQL Aggregate) from the second file to invoke the *as_sql* method.

sortx = BinSort(xTextString, offset=x, bincount=xbin, max=x1) sorty = 
BinSort(yTextString, offset=y, bincount=ybin, max=y1) 
annotated_query.annotate(x=sortx, y=sorty) cn = connections['default'] qn = 
SQLCompiler(annotated_query.query, cn, 'default').quote_name_unless_alias 
sortx_sql = sortx.aggregate.as_sql(qn, cn)[0] sorty_sql = 
sorty.aggregate.as_sql(qn, cn)[0]

The error that I'm getting(in l:6) in this implementation is, 

exception 'BinSort' object has no attribute 'aggregate'

As steps of debugging, i've tried to check if the BinSort instance has an 
attribute "aggregate", using 

hasattr(sortx, 'aggregate')

which has returned me False. But when I try to check by printing the 
aggregate attribute from inside the add_to_query method, I could very much 
see the attribute getting printed. Also, I've implemented this in the way 
specified in Django 1.8 doc, 
https://github.com/django/django/blob/stable/1.8.x/django/db/models/aggregates.py#L46
 

-- 
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/9cf87fa3-aae6-4c59-83e2-053b1ed98247%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DRF without login

2015-08-14 Thread Prabath Peiris
I set this in my setting.py file and it worked 

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [],
'DEFAULT_PERMISSION_CLASSES': [],
}

Thank You 
Prabath 


On Thursday, August 13, 2015 at 5:11:35 PM UTC-4, Xavier Ordoquy wrote:
>
>
> Le 13 août 2015 à 23:06, Prabath Peiris  > a écrit :
>
> Hi 
>
>
> Hi
>
> I am trying to implement a DRF in existing django project. I installed the 
> drf and set up APiView (class based) and add the get() to the class. When I 
> call this get method I get an error  as "Exception Value: no such table: 
> auth_user" and also create a db.sqlite3 database. how can I just simply 
> have a api (without models or without any authentications)
>
>
> You probably want to turn off the DRF authentication / permissions system (
> http://www.django-rest-framework.org/api-guide/authentication/#setting-the-authentication-scheme
>  and 
> http://www.django-rest-framework.org/api-guide/permissions/#setting-the-permission-policy
> ).
>
> Thanks 
> Prabath 
>
>
> Regards,
> Xavier,
> Linovia.
>
>

-- 
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/703dde50-11da-4da9-a39c-e21bbbf5491d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Possible Bug when using exclude on a GenericForeignKey / GenericRelation query.

2015-08-14 Thread Daniel H
Hi everyone.

I've been using django for almost a year now, but it's my first time 
posting here.

Anyway, I'm encountering an error which I think might be a bug. I've yet to 
try and replicate it as I thought posting here would be the better first 
step, as I might just be doing something incorrectly.

When I try a query with .exclude() on a table with a GenericForeignKey and 
a reverse Generic Relation on a different table, I get this:

AttributeError at /list

'GenericRelation' object has no attribute 'field'


Here is a mock up of my database structure:

class InternalOffer(models.Model):
user = models.ForeignKey('User')
status = models.CharField(max_length=64)
(more offer data...)
relation = GenericRelation(OfferJoin, related_query_name='offerquery')

class ExternalOffer(models.Model):
user = models.ForeignKey('User')
status = models.CharField(max_length=64)
(more offer data...)
relation = GenericRelation(OfferJoin, related_query_name='offerquery')

class OfferJoin(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
offer = GenericForeignKey('content_type', 'object_id')

I can filter fine, it's only the exclude that causes errors. Here is the 
code that causes the error:

offers = OfferCover.objects.filter(offerquery__user__id=request.user.id)
offers = offers.exclude(offerquery__status="Completed")

Here's the full callback:

Django Version: 1.8.2
Python Version: 2.7.6

Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in 
get_response
  132. response = wrapped_callback(request, 
*callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/auth/decorators.py" 
in _wrapped_view
  22. return view_func(request, *args, **kwargs)
File "/Users/path-to-project/project/views.py" in list
  136. offers = offers.exclude(o__status="Completed")
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in 
exclude
  686. return self._filter_or_exclude(True, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in 
_filter_or_exclude
  695. clone.query.add_q(~Q(*args, **kwargs))
File "/Library/Python/2.7/site-packages/django/db/models/sql/query.py" in 
add_q
  1304. clause, require_inner = self._add_q(where_part, 
self.used_aliases)
File "/Library/Python/2.7/site-packages/django/db/models/sql/query.py" in 
_add_q
  1332. allow_joins=allow_joins, split_subq=split_subq,
File "/Library/Python/2.7/site-packages/django/db/models/sql/query.py" in 
build_filter
  1180.   can_reuse, e.names_with_path)
File "/Library/Python/2.7/site-packages/django/db/models/sql/query.py" in 
split_exclude
  1562. trimmed_prefix, contains_louter = 
query.trim_start(names_with_path)
File "/Library/Python/2.7/site-packages/django/db/models/sql/query.py" in 
trim_start
  1989. join_field = path.join_field.field

Exception Type: AttributeError at /list
Exception Value: 'GenericRelation' object has no attribute 'field'

I've read the documentation multiple times and haven't come across anything 
usefull. I know that filtering GFKs alone won't work, but both filtering 
and excluding should work with the reverse Generic Relation.

Thanks!
- Daniel Harris

-- 
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/b44b0d43-2499-4075-8842-8c9fb76d3160%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django: "Fake" multiple inheritance

2015-08-14 Thread Daniel H
Hi Michael.

First of all, setting the pk to the pk of a different model will do nothing.

You can do this however, using Foreign Keys 


restaurant = models.ForeignKey('Restautant')

Then declare a new hotel object like this:

restaurant = Restaurant.objects.get(name='Will soon be a hotel')
Hotel.objects.create(restaurant=restaurant.pk)

What does the "Place" table represent?


On Friday, August 14, 2015 at 7:35:26 AM UTC-7, mic...@herrmann.io wrote:
>
> Hi all,
>
> suppose I have the following model structure
>
> from django.db import models
> 
> class Place(models.Model):
> name = models.CharField(max_length=50)
> 
> class Restaurant(Place):
> ...
> 
> class Hotel(Place):
> ...
>
> I already have a Restaurant in my database. This Restaurant is now also 
> becoming a Hotel. I would like to declare this in the database as follows:
>
> restaurant = Restaurant.objects.get(name='Will soon be a hotel')
> Hotel.objects.create(pk=restaurant.pk)
>
> Is this a safe thing to do?
>
> Thanks,
> Michael
>

-- 
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/c270d98c-7a14-4870-9f04-3ccfcb3abeb3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Learning Python and Django and should I?? (I have a year of 10 or so hours a week)

2015-08-14 Thread Rotimi Ajayi-Dopemu
Hi all,
I am sure this question has been beaten into the ground but hopefully I can 
get some specific insight so I don't waste time in the future. Thanks in 
advance.

The question:
I have a year to learn a new programming language for web application 
development. I will be learning concurrently with going to school so I have 
about 10 hrs a week give or take. So the question is this should I learn 
Ruby on Rails or Python/Django???

Background Info about why:
I am a student studying Cognitive Science and want to work as either a UX 
designer or a Full Stack Engineer, I am leaning towards Full Stack 
Engineering and designing more for the front end in my after hours. I don't 
have a serious girlfriend (lol) and my life is pretty simple so I know this 
is what I want to do. I am committed. I know PHP fairly well and can use 
Wordpress and Joomla for whatever. I am familiar with MVC through use of a 
popular PHP framework called Codeigniter. Oh yeah, I used C++ pretty 
heavily about 10 years ago building Windows Applications...and loved it.

What I will be using it for:
After I graduate in a year and after learning the language I decide on I 
plan to develop a full blown web application. I don't know if this is too 
ambitious but all I'm willing to say now is it is like Pintrest but not a 
clone. I have fully developed the concept for a long time now and will have 
the features down pat by then. My goal is to invest my time on a prototype 
and release it, then hopefully get with a team or even investors if it 
works and develop it more. If it doesn't work out then Plan B is to use my 
skill-set in a full time position with a company in a tech hub somewhere in 
the US. Plan B might turn into Plan A in a year depending on my money 
situation.

So there are three aspects to this question: Should I learn Django/Python 
or Ruby on Rails? is Plan A(the web app) feasible with just me and 
Django/Python? How does Python fair in the work market?

I know all this may seem like a lot to ask but this is really just a test 
of this forums activity. I have been pretty avid on staying with PHP or 
maybe going back to C++ because this HTML/CSS situation I usually work with 
these days tends to get on my nerves. 

Last thing to add for this thread (I swear) is: one thing that really irks 
me about web development is the lack of real debugging tools that work 
flawlessly. Maybe it is just I haven't learned them yet but I know in PHP 
you are stuck with using Xdebug through your browser (although I just found 
a new debugger that only works in recent versions of PHP) so if anyone 
could just give a 1+ to integrated debugging with Python Django that would 
be great.

Thanks again if you read this far.
Feel free to contact me if you have a similar web application in the works, 
I have no doubt there probably is.

-- 
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/4c01a2c3-50f1-4123-b0b2-4197222d6595%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Learning Python and Django and should I?? (I have a year of 10 or so hours a week)

2015-08-14 Thread Jonathan Baker
Have you written any Python or Ruby? If so, do you have a preference?
Both are high-level languages, and the dominant web framework for each
(Django and Rails) are mature and stable. I'd at least read and write
some code for each and see if the syntax of the language and the
semantics of the framework strike your fancy. Ruby didn't click with
me like Python did, so three and a half years after ditching PHP here
I am. I love how easy Python is to read, and I've thoroughly enjoyed
working with Django (esp. after Drupal, WordPress and a bit of
CodeIgniter).

Concerning jobs, I'm based in Denver, CO and there are many more RoR
opportunities here than Django. I can't speak for other markets, but
I'm moving to Oregon next year so I'll find out soon enough;)

As for debugging, the Django Debug Toolbar
(https://github.com/django-debug-toolbar/django-debug-toolbar) is
quite popular. That combined with vim-flake8
(https://github.com/nvie/vim-flake8) and PDB
(https://docs.python.aorg/2/library/pdb.html) get me out of most hairy
situations I find for myself.

Hope this helps a bit,
JDB

On Fri, Aug 14, 2015 at 3:20 PM, Rotimi Ajayi-Dopemu  wrote:
> Hi all,
> I am sure this question has been beaten into the ground but hopefully I can
> get some specific insight so I don't waste time in the future. Thanks in
> advance.
>
> The question:
> I have a year to learn a new programming language for web application
> development. I will be learning concurrently with going to school so I have
> about 10 hrs a week give or take. So the question is this should I learn
> Ruby on Rails or Python/Django???
>
> Background Info about why:
> I am a student studying Cognitive Science and want to work as either a UX
> designer or a Full Stack Engineer, I am leaning towards Full Stack
> Engineering and designing more for the front end in my after hours. I don't
> have a serious girlfriend (lol) and my life is pretty simple so I know this
> is what I want to do. I am committed. I know PHP fairly well and can use
> Wordpress and Joomla for whatever. I am familiar with MVC through use of a
> popular PHP framework called Codeigniter. Oh yeah, I used C++ pretty heavily
> about 10 years ago building Windows Applications...and loved it.
>
> What I will be using it for:
> After I graduate in a year and after learning the language I decide on I
> plan to develop a full blown web application. I don't know if this is too
> ambitious but all I'm willing to say now is it is like Pintrest but not a
> clone. I have fully developed the concept for a long time now and will have
> the features down pat by then. My goal is to invest my time on a prototype
> and release it, then hopefully get with a team or even investors if it works
> and develop it more. If it doesn't work out then Plan B is to use my
> skill-set in a full time position with a company in a tech hub somewhere in
> the US. Plan B might turn into Plan A in a year depending on my money
> situation.
>
> So there are three aspects to this question: Should I learn Django/Python or
> Ruby on Rails? is Plan A(the web app) feasible with just me and
> Django/Python? How does Python fair in the work market?
>
> I know all this may seem like a lot to ask but this is really just a test of
> this forums activity. I have been pretty avid on staying with PHP or maybe
> going back to C++ because this HTML/CSS situation I usually work with these
> days tends to get on my nerves.
>
> Last thing to add for this thread (I swear) is: one thing that really irks
> me about web development is the lack of real debugging tools that work
> flawlessly. Maybe it is just I haven't learned them yet but I know in PHP
> you are stuck with using Xdebug through your browser (although I just found
> a new debugger that only works in recent versions of PHP) so if anyone could
> just give a 1+ to integrated debugging with Python Django that would be
> great.
>
> Thanks again if you read this far.
> Feel free to contact me if you have a similar web application in the works,
> I have no doubt there probably is.
>
> --
> 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/4c01a2c3-50f1-4123-b0b2-4197222d6595%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
Jonathan D. Baker
https://voltaic.io

-- 
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 g

Re: Learning Python and Django and should I?? (I have a year of 10 or so hours a week)

2015-08-14 Thread James Schneider
I came upon similar crossroads several years ago. Granted, I'm not a
programmer by trade, but I do have several personal projects that I work
on. I had done some large module development for Drupal in PHP over several
years, and once I reached the point where I was fighting to override Drupal
more than I was spending time adding new functionality, I started looking
at web frameworks rather than modifying CMS platforms. I was also growing
tired of the PHP inconsistencies and the inability to properly debug.

After some research, I came down to Perl/Mason, Ruby/Rails and
Python/Django. I was already familiar with Perl, less so with Python from
work, and had no experience with Ruby. After reading the flame wars between
the languages on forums with posters asking the same question, I decided
the best way was just to dive in and try it myself. I didn't particularly
want to go down the Perl route, as I had spent countless hours fighting
with CPAN getting modules installed for work scripts. I decided to start
with Ruby and Rails. This was around the time that 1.8 was dubbed a
horrible mess and 1.9 was still fresh and slightly buggy. After fighting
with that issue, I spent several days trying to figure out what was
required for RoR, installing gems, and learning Ruby in general. I still to
this day have no idea what a symbol is, nor the proper time to use it.
After a few weeks of trying and working around all of the system-specific
issues I was having, I think I managed to get a working version of a basic
site up. Having 'conquered' RoR, I moved on to Python/Django. Python and
Ruby are somewhat similar in terms of layout and even syntax at a very
basic level, so the transition wasn't difficult. What attracted me to
Python/Django, though, is the lack of 'magic' behind the scenes. I felt
like RoR was making decisions for me behind the scenes, and I had little
control. Not that I necessarily needed control at that point, but given my
previous experience with Drupal/PHP, it gave me reason for pause.
Python/Django is clean, without magic, easy to read, and almost forces you
to be a good programmer with indentations, simple syntax, etc. After
running through the Django tutorial in a couple of hours (1.3 had just come
out at the time with CBV's as the prominent new feature), I was extremely
hooked, considering the same process in RoR was a few days of effort. I
also felt the philosophy and intent of Python better aligned with my
personal inclinations. Simple, clean, big focus on backwards compatibility
both in the language and Django (a large problem that I had with Drupal).
Ruby felt much more bleeding edge, fast-paced, and 'magical'. Call me a
control freak, I like to know what my code is actually doing. Makes for
easier troubleshooting later. Python also had excellent cross-platform
support, and native support within Ubuntu/Debian/Gentoo linux, since a fair
portion of their tools are written in Python. Pip makes installing (and
version control) ridiculously easy, much easier to navigate than gem repos
or CPAN.

All that aside, the best advice I can give you is just to try each out and
figure out which one 'feels right' for you. Both have more than enough
market share as a viable career path. Given your field of study, Python may
be a better choice for you considering the immense amount of scientific
work done with Python. I've never heard of Ruby having such a reputation
(but that doesn't mean it isn't being done).

As far as Python debugging tools go, I would definitely look into PyCharm,
which has a free community edition with a built-in debugger. It handles
Django with ease, and the licensed version has extra special goodies for
Django specifically, probably worth the cost if you are serious about
developing the application you are talking about.

-James


On Fri, Aug 14, 2015 at 2:20 PM, Rotimi Ajayi-Dopemu 
wrote:

> Hi all,
> I am sure this question has been beaten into the ground but hopefully I
> can get some specific insight so I don't waste time in the future. Thanks
> in advance.
>
> The question:
> I have a year to learn a new programming language for web application
> development. I will be learning concurrently with going to school so I have
> about 10 hrs a week give or take. So the question is this should I learn
> Ruby on Rails or Python/Django???
>
> Background Info about why:
> I am a student studying Cognitive Science and want to work as either a UX
> designer or a Full Stack Engineer, I am leaning towards Full Stack
> Engineering and designing more for the front end in my after hours. I don't
> have a serious girlfriend (lol) and my life is pretty simple so I know this
> is what I want to do. I am committed. I know PHP fairly well and can use
> Wordpress and Joomla for whatever. I am familiar with MVC through use of a
> popular PHP framework called Codeigniter. Oh yeah, I used C++ pretty
> heavily about 10 years ago building Windows Applications...and loved it.
>
> What I will be using it for:
> A

Re: Learning Python and Django and should I?? (I have a year of 10 or so hours a week)

2015-08-14 Thread Andrew Farrell
One tool for debugging that I would actually use isn't actually a debugger
although ipdb is great .
If you decide to go with python/django, I would strongly consider using the
book Test Driven Web Development with Python
. It not
only provides a good django introduction, but the approach it advocates of
writing tests first makes it a lot easier to find bugs quickly and when you
find a bug, to nail down exactly what causes it and when it is fixed.

On Fri, Aug 14, 2015 at 5:34 PM, James Schneider 
wrote:

> I came upon similar crossroads several years ago. Granted, I'm not a
> programmer by trade, but I do have several personal projects that I work
> on. I had done some large module development for Drupal in PHP over several
> years, and once I reached the point where I was fighting to override Drupal
> more than I was spending time adding new functionality, I started looking
> at web frameworks rather than modifying CMS platforms. I was also growing
> tired of the PHP inconsistencies and the inability to properly debug.
>
> After some research, I came down to Perl/Mason, Ruby/Rails and
> Python/Django. I was already familiar with Perl, less so with Python from
> work, and had no experience with Ruby. After reading the flame wars between
> the languages on forums with posters asking the same question, I decided
> the best way was just to dive in and try it myself. I didn't particularly
> want to go down the Perl route, as I had spent countless hours fighting
> with CPAN getting modules installed for work scripts. I decided to start
> with Ruby and Rails. This was around the time that 1.8 was dubbed a
> horrible mess and 1.9 was still fresh and slightly buggy. After fighting
> with that issue, I spent several days trying to figure out what was
> required for RoR, installing gems, and learning Ruby in general. I still to
> this day have no idea what a symbol is, nor the proper time to use it.
> After a few weeks of trying and working around all of the system-specific
> issues I was having, I think I managed to get a working version of a basic
> site up. Having 'conquered' RoR, I moved on to Python/Django. Python and
> Ruby are somewhat similar in terms of layout and even syntax at a very
> basic level, so the transition wasn't difficult. What attracted me to
> Python/Django, though, is the lack of 'magic' behind the scenes. I felt
> like RoR was making decisions for me behind the scenes, and I had little
> control. Not that I necessarily needed control at that point, but given my
> previous experience with Drupal/PHP, it gave me reason for pause.
> Python/Django is clean, without magic, easy to read, and almost forces you
> to be a good programmer with indentations, simple syntax, etc. After
> running through the Django tutorial in a couple of hours (1.3 had just come
> out at the time with CBV's as the prominent new feature), I was extremely
> hooked, considering the same process in RoR was a few days of effort. I
> also felt the philosophy and intent of Python better aligned with my
> personal inclinations. Simple, clean, big focus on backwards compatibility
> both in the language and Django (a large problem that I had with Drupal).
> Ruby felt much more bleeding edge, fast-paced, and 'magical'. Call me a
> control freak, I like to know what my code is actually doing. Makes for
> easier troubleshooting later. Python also had excellent cross-platform
> support, and native support within Ubuntu/Debian/Gentoo linux, since a fair
> portion of their tools are written in Python. Pip makes installing (and
> version control) ridiculously easy, much easier to navigate than gem repos
> or CPAN.
>
> All that aside, the best advice I can give you is just to try each out and
> figure out which one 'feels right' for you. Both have more than enough
> market share as a viable career path. Given your field of study, Python may
> be a better choice for you considering the immense amount of scientific
> work done with Python. I've never heard of Ruby having such a reputation
> (but that doesn't mean it isn't being done).
>
> As far as Python debugging tools go, I would definitely look into PyCharm,
> which has a free community edition with a built-in debugger. It handles
> Django with ease, and the licensed version has extra special goodies for
> Django specifically, probably worth the cost if you are serious about
> developing the application you are talking about.
>
> -James
>
>
> On Fri, Aug 14, 2015 at 2:20 PM, Rotimi Ajayi-Dopemu 
> wrote:
>
>> Hi all,
>> I am sure this question has been beaten into the ground but hopefully I
>> can get some specific insight so I don't waste time in the future. Thanks
>> in advance.
>>
>> The question:
>> I have a year to learn a new programming language for web application
>> development. I will be learning concurrently with going to school so I have
>> about 10 hrs a week give or take. So