The 'address' field is an FK to the Address model (hence the reference to
'address_id'), and you'll either need to 1) add null=True to the address
field definition in UserPrefs and update your migrations and allow a
UserPref model to not be connected to an Address model, 2) find the right
Address model within your various create/save() method calls and include it
when creating a UserPref object, or 3) Create a new Address object, save
it, and then pass it in when creating the UserPref object.

Sounds like option 3 is the way you want to go since you are including a
string that can be used to create an Address object. That would probably be
best in your create() call so that a new Address object isn't created
whenever you update your UserPref object.

Just keep in mind that you are creating two objects in this view, one
UserPref, and an Address that gets attached to your UserPref. Simply
setting userpref.address to "XYZ" is incorrect.

-James



On Tue, Jun 2, 2015 at 5:18 PM, Shekar Tippur <ctip...@gmail.com> wrote:

> James,
> You are right. I am able to get past that issue.
> The next stumbling block is with
>
> null value in column "address_id" violates not-null constraint
> DETAIL:  Failing row contains (10, Likes, null, null).
>
> Here is my curl
>
> curl -H  "Authorization: Bearer $usertoken" -H "Content-Type:
> application/json" -X POST -d '{"address":"XYZ","prefs":"Likes"}' http://
> ${endpoint}/addPrefs
>
>
> How do I pass the address name so that it gets translated to an id in the
> background.
>
>
> - Shekar
>
> --
> 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/8b031b31-3b95-43cd-bcd7-cb46b315703d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8b031b31-3b95-43cd-bcd7-cb46b315703d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> 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%2BciWNHnoggv59vKvfMVMBQP%3DfGii6FkkHrMeUyeyp9NjLRg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to