Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7768615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:57:30+00:00 2026-06-01T15:57:30+00:00

In my current code, a user has a list of goals he has joined.

  • 0

In my current code, a user has a list of goals he has joined. I want an API endpoint to expose all of the user’s joined goals. I want to be able to post, put, and get to this API endpoint. It will get a list of the joined goals, add a goal to the joined goals list, or make an update to the joined goals list.

# Joined Goal Resource
class JoinedGoalResource(ModelResource):
  user = fields.ForeignKey(UserResource, 'user')
  joined_goals = fields.ManyToManyField(GoalResource, 'joined_goals', full=True)

  class Meta:
    authentication = Authentication()
    authorization = Authorization()
    queryset = UserProfile.objects.all()
    resource_name = 'joined_goal'
    allowed_methods = ['get', 'post', 'put']
    filtering = {
      'user': ALL_WITH_RELATIONS
    }

The problem with the above code is that it uses UserProfile model as its queryset so if I do a post, get, or put on the API endpoint, it will effect the UserProfile rather than the user’s joined_goals.

Edit:
I have changed my code so that the joined resource overrides the obj_create method and just adds to the logged in user’s joined goal list. The problem is that the method requires me to return a bundle. How do I create the bundle to return? I am doing something like this:

goal_resource = GoalResource
goal_obj = goal_resource.obj_get(pk=1)
goal_bundle = goal_resource.build_bundle(obj=goal_obj, request=request)
return goal_bundle

But the obj_get doesn’t work when taking in an argument of pk=1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:57:31+00:00Added an answer on June 1, 2026 at 3:57 pm

    The solution can be quite simple.

    You could implement a regular resource (forgetting about user ownership) and then follow the “Creating per-user resources” section of Tastypie cookbook to narrow the list returned by GET and ensure that the newly created objects are owned by the current user (POST).

    With respect to PUT, you just need authorization class which ensures the user is only authorized to update his/her own goals. This is the trickiest part (but not hard), just make sure that the value of user attribute of the goal bundle is the same a request.user when the method is PUT otherwise raise an exception and you’re done 🙂

    So with above you’d have following URIs:

    GET,POST,PUT /api/users/ #for interaction with Users
    GET,POST,PUT /api/user-goals/ #for interaction with Goals
    

    and you could introduce (for GET):

    GET /api/users/goals/ #for displaying user goals in more natural way
    

    by following Nested Resources section of the cookbook

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a global object that represents the current user in Code
I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
I have a problem with obtaining the current user location. Code at first works
we've created a custom webpart to display announcements from all lists a user has
My ASP.NET MVC intranet app has a data repository that uses current user's Windows
current code I've built function to do something over collection of jQuery elements: var
My current code looks like the following. How can I pass my array to
My current code is this $swift = email::connect(); $swift->setSubject('hello') ->setFrom(array('alex@example.com.au' => 'Alex')) ->setTo(array('alex@example.com.au' =>
My current code needs to read foreign characters from the web, currently my solution
Update Sir this is current code of my web page.I made changes according to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.