Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Piston and foreignkey
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
luupux  
View profile  
 More options Feb 10 2010, 8:19 am
From: luupux <luu...@gmail.com>
Date: Wed, 10 Feb 2010 05:19:33 -0800 (PST)
Local: Wed, Feb 10 2010 8:19 am
Subject: Piston and foreignkey
Hello i have a problem with simple application , but i not understand
where is the my error.

But I know the problem and is ForeignKey to model listurl because if I
use
another model without foreigkey everything starts working
Excuse my bad English
I know the question is stupid but I do not understand what mistake
Thanks
###################################################################
Traceback (most recent call last):

  File "/home/lupux/DevelDir/DJANGO/siteupdate/../siteupdate/api/
handlers.py", line 28, in create
    urlip=attrs['urlip'])

  File "/usr/lib/python2.5/site-packages/django/db/models/base.py",
line 311, in __init__
    setattr(self, field.name, rel_obj)

  File "/usr/lib/python2.5/site-packages/django/db/models/fields/
related.py", line 273, in __set__
    self.field.name, self.field.rel.to._meta.object_name))

ValueError: Cannot assign "u'servicetype'": "listurl.servicetype" must
be a "servicetype" instance.
* Closing connection #0

####################################################

Snip code  handler.py

from piston.handler import BaseHandler, AnonymousBaseHandler
from piston.utils import rc, require_mime, require_extended
import re

from siteupdate.proxy.models import
listurlForm,listurl,hostserver,servicetype

class listurlHandler(BaseHandler):
        model = listurl
        anonymous = 'AnonymouslisturlHandler'
        fields = ('urlip','hostserver','servicetype')

        def create(self, request):
                """
                Creates a new blogpost.
                """
                attrs = self.flatten_dict(request.POST)
                print rc.CREATED
                if self.exists(**attrs):
                        print "DUCLICATO"
                        print attrs
                        return rc.DUPLICATE_ENTRY
                else:
                        print "NUOVO RECORD"
                        inspl=listurl(hostserver=attrs['hostserver'],

servicetype=attrs['servicetype'],
                                        urlip=attrs['urlip'])
                        return inspl

##############################################################

Snip code  model.py

from django.db import models
from django.forms import ModelForm
#Table define listurl for service and host
class servicetype(models.Model):
        servicetype=models.CharField(max_length=200)
        descr=models.CharField(max_length=200)
        def __unicode__(self):
                return self.servicetype

class servicetypeForm(ModelForm):
        class Meta:
                model = servicetype

#Table define hostserver referenze
class hostserver(models.Model):
        hostserver=models.CharField(max_length=200)
        aliasurl=models.CharField(max_length=200)
        def __unicode__(self):
                return self.hostserver

class hostserverForm(ModelForm):
        class Meta:
                model = hostserver

class listurl(models.Model):
        servicetype =
models.ForeignKey('servicetype',verbose_name="Servizio squid/
dansguardian")
        hostserver  =
models.ForeignKey('hostserver',verbose_name="Server associato")
        urlip=models.CharField(max_length=200,verbose_name="domino/ip
da gestire")

        def __unicode__(self):
                return self.urlip
        #def get_absolute_url(self):
#               return self.urlip

        def get_absolute_url(self):
                return self.urlip

#Table type service  squid/danguardian
class listurlForm(ModelForm):
        class Meta:
                model = listurl

#################################################


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
luupux  
View profile  
 More options Feb 15 2010, 4:51 am
From: luupux <luu...@gmail.com>
Date: Mon, 15 Feb 2010 01:51:19 -0800 (PST)
Local: Mon, Feb 15 2010 4:51 am
Subject: Re: Piston and foreignkey
hello
please help my
can you tell me  link for simple example for piston and model  on
foreginkey?

On 10 Feb, 14:19, luupux <luu...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Foulis  
View profile  
 More options Feb 19 2010, 8:32 am
From: Stefan Foulis <stefan.fou...@gmail.com>
Date: Fri, 19 Feb 2010 05:32:28 -0800 (PST)
Local: Fri, Feb 19 2010 8:32 am
Subject: Re: Piston and foreignkey
I'm having the same problem. I'm confused about how I can change the
value of a Model field that is a ForeignKey in a PUT or POST request.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ty ty  
View profile  
 More options Feb 19 2010, 9:36 am
From: ty ty <luu...@gmail.com>
Date: Fri, 19 Feb 2010 15:36:57 +0100
Local: Fri, Feb 19 2010 9:36 am
Subject: Re: Piston and foreignkey
you can not assign a  string in  a foregin key value

value in  handlery.py  as a string  but  foreginkey as method

I do not know how to use a field in foreginkey in def create .

excuse my bad English

Model.py
class listurl(models.Model):
        servicetypelist = models.ForeignKey('servicetype')
        urlip=models.CharField(max_length=200)

hander.py
listurl(servicetypelist=attrs["value"],urlip=attrs['urlip'])

attrs["value"] = is string    and not good  because  servicetypelist
not  a string but foreginkey method

im a newbye

2010/2/19 Stefan Foulis <stefan.fou...@gmail.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Foulis  
View profile  
 More options Feb 19 2010, 11:28 am
From: Stefan Foulis <stefan.fou...@gmail.com>
Date: Fri, 19 Feb 2010 08:28:16 -0800 (PST)
Local: Fri, Feb 19 2010 11:28 am
Subject: Re: Piston and foreignkey
I had a look at the piston sourcecode. As far as I can tell foreign
keys are not supported for create and update.

see http://bitbucket.org/yml/django-piston/src/72c72e0b4b7e/piston/handle...
(create)
and  http://bitbucket.org/yml/django-piston/src/72c72e0b4b7e/piston/handle...
(update)

For my particular use case I did an override of the create method on
the handler (see http://dpaste.com/hold/161697/) and added special
treatment for the ForeignKey I'm interested in ('myfkfieldname'). And
I did something similar for the update method.
This could be extended to actually look in _meta of the model to
evaluate all ForeignKeys automatically.

Isn't there a security issue here? No matter what is in `fields` on
the handler, if the client has update permissions on a model it can
change all of the fields on the model.

--
Stefan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anverc  
View profile  
 More options Mar 17 2010, 4:43 pm
From: Anverc <anv...@gmail.com>
Date: Wed, 17 Mar 2010 13:43:32 -0700 (PDT)
Local: Wed, Mar 17 2010 4:43 pm
Subject: Re: Piston and foreignkey
I've taken what Stefan suggested and came up with a way to deal with
ForeignKeys somewhat automagically (at least keeping as much code
reusable as possible).  Have a look at my implementation and provide
feedback please! :)

the code and some preliminary explanations of it are here:
http://blog.bennyland.com/2010/03/17/extending-pistons-basehandler-fo...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »