django - class based view store post data

2015-05-30 Thread Shekar Tippur
Hello,

I am trying to use class based view to post data.
I have come across a weird issue. It is not saving data in the backend. I 
get an error:

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


I have searched on google to see explanation on this error but could not 
understand the explanation. Appreciate if someone can shed some light on this.


Here is my model:

class UserPrefs(models.Model):
Preferences = (
(1,'Likes'),
(1,'Dislikes'),
(1,'Shared'),
(1,'Rejected')
)
user = models.ForeignKey('auth.User', related_name='Hello')
name = models.ForeignKey(Stock)
value = models.CharField(max_length=20,choices=Preferences)

class Meta:
#managed = False
db_table = 'user_pref'

def save(self, *args, **kwargs):
super(Hello, self).save(*args, **kwargs)


class AddToUserProfile(generics.GenericAPIView):
permission_classes = 
(permissions.IsAuthenticatedOrReadOnly,IsOwnerOrReadOnly)
queryset = UserPrefs.objects.all()
serializer_class = UserPrefSerializer
lookup_fields = ('id')
def get(self, request, *args, **kwargs):
return HttpResponse('Hello there!')

def post(self, request, *args, **kwargs):
self.object = self.get_object()
context = self.get_context_data(object=self.object)
#eturn self.render_to_response(context)
def create(self, serializer):
serializer.save(owner=self.request.user)


Serializer code:


class UserPrefSerializer(serializers.ModelSerializer):
owner = serializers.ReadOnlyField(source='owner.username')
class Meta:
model = UserPrefs
fields = ( 'owner', 'name', 'value')
depth = 1


Url.py entry:

url(r'^Hello/setPrefs', views.AddToUserProfile.as_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/6dbb2532-3bc3-4108-b1c9-9d48337fb02c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CSRF verification failed when I use smart phone

2015-05-30 Thread Michael Greer
We have started seeing this behavior occasionally. No code change in this 
area, but sometimes (esp on phones) the CSRF cookie is wrong.

Our guess is too many cookies on the domain, but it is difficult to prove 
this. Indeed, opening a new browser session resolves it... temporarily.

-Mike

On Tuesday, January 6, 2015 at 3:09:46 AM UTC-6, Sugita Shinsuke wrote:
>
> Hello.
>
> When I use Django via my smart phone Android and iOS.
> The error sometimes occurred.
>
> Forbidden (403)
> CSRF verification failed. Request aborted.
> Help
> Reason given for failure:
> CSRF token missing or incorrect.
>
> In general, this can occur when there is a genuine Cross Site Request 
> Forgery, or when Django's CSRF mechanism has not been used correctly. For 
> POST forms, you need to ensure:
> Your browser is accepting cookies.
> The view function uses RequestContext for the template, instead of Context.
> In the template, there is a {% csrf_token %} template tag inside each POST 
> form that targets an internal URL.
> If you are not using CsrfViewMiddleware, then you must use csrf_protect on 
> any views that use the csrf_token template tag, as well as those that 
> accept the POST data.
> You're seeing the help section of this page because you have DEBUG = True 
> in your Django settings file. Change that to False, and only the initial 
> error message will be displayed.
> You can customize this page using the CSRF_FAILURE_VIEW setting.
>
> I append django.middleware.csrf.CsrfViewMiddleware', of MIDDLEWARE_CLASSES 
> in settings.py
>
> I use
> Python 2.7.5
> Django 1.6.4
>
> Anyone who know this matter, please help.
>
>

-- 
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/89d20584-d3bf-4104-b642-0f519c4deb10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Migrate command does not respect options for db connections?

2015-05-30 Thread George Silva
Context:

Django 1.7.1
PostgreSQL 9.4

I have the following database entry in settings:

DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'xpto',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'localhost',
'PORT': '5432',
'OPTIONS': {
'options': '-c search_path=xpto,public'
}
}
}


And the following model:

class ModelA(models.Model):
att_a = models.CharField(max_length=10)

I' just created a migration with makemigrations for this app. It does not
have any indication of schema, whatsoever.

When I ran the migration, with migrate, the table ended up on the public
schema.

Bug?

-- 
George R. C. Silva
Sigma Geosistemas LTDA

http://www.sigmageosistemas.com.br/

-- 
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/CAGyPVTvGh7HTGGyTgj4Qu8cpxp9ddDTmBY7si4uoq9Z484%2BX8w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Upgrade to django 1.7- ImproperlyConfigured -Tastypie label duplicate? help

2015-05-30 Thread dc
Were you able to solve the problem @amarshall? I have the exact same error, 
do let me know please!

On Tuesday, March 31, 2015 at 8:04:23 PM UTC+5:30, Filipe Ximenes wrote:
>
> Thats strange.
> Are you using pip to install dependencies? Try uninstalling everything and 
> reinstalling again. 
> Make sure INSTALLED_APPS is not being defined somewhere else in the code. 
> Does the error persists if you set DEBUG = False locally?
>
> On Tue, Mar 31, 2015 at 10:21 AM, amarshall  > wrote:
>
>> Hi Filipe,
>>
>> I have few apps installed. When I comment out the tastypie line my app 
>> builds but gets an error in production because tastypie app isn't found. 
>> Here it is:
>>
>> INSTALLED_APPS = (
>> 'django.contrib.admin',
>> 'django.contrib.auth',
>> 'django.contrib.contenttypes',
>> 'django.contrib.sessions',
>> 'django.contrib.messages',
>> 'django.contrib.staticfiles',
>> 'rest_framework',
>># 'south',   // commented out after upgrade to Django 1.7
>> 'tastypie',
>> 'lokal',#my app
>> )
>>
>>
>>
>> On Tuesday, March 31, 2015 at 5:52:55 AM UTC-4, Filipe Ximenes wrote:
>>>
>>> Can you show us your INSTALED_APPS?
>>> It may be the case you have a lot of apps installed and is not seeing a 
>>> duplicate reference to tastypie.
>>> On Mar 29, 2015 9:43 PM, "amarshall"  wrote:
>>>
 Hi,

  So I updated my django project from django 1.6 to 1.7.7 and when I run 
 "python manage.py migrate" I get this error stating that I have a 
 duplicate 
 label. 

 Here's the traceback

   Creating tables...
   Installing custom SQL...
   Installing indexes...
 Running migrations:
   Applying tastypie.0001_initial...Traceback (most recent call last):
   File "manage.py", line 11, in 
 execute_from_command_line(sys.argv)
   File "/usr/local/lib/python2.7/dist-packages/django/core/
 management/__init__.py", line 385, in execute_from_command_line
 utility.execute()
   File "/usr/local/lib/python2.7/dist-packages/django/core/
 management/__init__.py", line 377, in execute
 self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/usr/local/lib/python2.7/dist-packages/django/core/
 management/base.py", line 288, in run_from_argv
 self.execute(*args, **options.__dict__)
   File "/usr/local/lib/python2.7/dist-packages/django/core/
 management/base.py", line 338, in execute
 output = self.handle(*args, **options)
   File "/usr/local/lib/python2.7/dist-packages/django/core/
 management/commands/migrate.py", line 161, in handle
 executor.migrate(targets, plan, fake=options.get("fake", False))
   File "/usr/local/lib/python2.7/dist-packages/django/db/
 migrations/executor.py", line 68, in migrate
 self.apply_migration(migration, fake=fake)
   File "/usr/local/lib/python2.7/dist-packages/django/db/
 migrations/executor.py", line 96, in apply_migration
 if self.detect_soft_applied(migration):
   File "/usr/local/lib/python2.7/dist-packages/django/db/
 migrations/executor.py", line 140, in detect_soft_applied
 apps = project_state.render()
   File "/usr/local/lib/python2.7/dist-packages/django/db/
 migrations/state.py", line 57, in render
 self.apps = Apps([AppConfigStub(label) for label in 
 sorted(self.real_apps 
 + list(app_labels))])
   File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py"
 , line 56, in __init__
 self.populate(installed_apps)
   File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py"
 , line 89, in populate
 "duplicates: %s" % app_config.label)
 django.core.exceptions.ImproperlyConfigured: Application labels aren't 
 unique, duplicates: tastypie


 Not sure what to do here. I remove tastypie from the list of 
 INSTALLED_APPS in my settings and everything works fine. but I do need it. 
 Any suggestions ?

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django-users...@googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.
 Visit this group at http://groups.google.com/group/django-users.
 To view this discussion on the web visit https://groups.google.com/d/
 msgid/django-users/7e4cfbf8-d3e0-4e0e-a38c-b83930ffa3b6%
 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 d