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 8574525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:29:37+00:00 2026-06-11T19:29:37+00:00

I have 2 resources that are linked by a foreignKey I would like to

  • 0

I have 2 resources that are linked by a foreignKey

I would like to make the AUser resource read-only when creating/modifying AJob

class AUser(ModelResource):
    class Meta:
        queryset = User.objects.all()
        resource_name = 'user'
        authentication = SessionAuthentication()
        authorization = Authorization()
        excludes = ['email', 'password', 'is_superuser', 'is_staff', 'is_active', 'date_joined', 'last_login']
    def can_update(self):
        return False  
    def can_create(self):
        return False
    def can_delete(self):
        return False
    def apply_authorization_limits(self, request, object_list):
        return object_list.filter(pk=request.user.pk)

class AJob(ModelResource):
    user = fields.ForeignKey( AUser, 'user', full=True)
    paused = fields.BooleanField(attribute='isPaused', readonly=True)
    hasRules = fields.BooleanField(attribute='hasRules', readonly=True)
    class Meta:
        queryset = Job.objects.all()
        resource_name = 'job'
        authentication = SessionAuthentication()
        api_name = 'v1'
        authorization = Authorization()
        allowed_methods = ['get', 'post', 'delete']

    def obj_create(self, bundle, request=None, **kwargs):
        return super(AJob, self).obj_create(bundle, request, user=request.user)

    def apply_authorization_limits(self, request, object_list):
        return object_list.filter(user=request.user)

I tried adding readonly=True to the foreignKey directly but then it’s ignored when hydrating
and get a constraint violation because user is null

if in my POST AJob request I append

“user”:{“id”:”5″,”is_staff”:false}

5 being the current user

the User model get updated, removing the admin role

it seems that tastypie when doing save_related does not check any authorization

How can I make this User resource read-only ?

I am using tastypie v0.9.12-alpha

  • 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-11T19:29:39+00:00Added an answer on June 11, 2026 at 7:29 pm

    You can modify the save_related method inside the AJob resource and define it not to modify the AUser. You can define the ForeignKey do be readonly as you wanted to but then you have to supply the dehydrate_user method and inside get the value that you want to return. It will be something like return bundle['data'].user.

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

Sidebar

Related Questions

I have an Eclipse plugin project that has several file resources that I would
Googling this does little good, as you can imagine. Does anyone have resources that
I have an image that I have in my bundle resources that I need
I need to know because I have to explicitly close some remote resources that
I have a DataTemplate within my Window's Resources section that creates a TextBlock with
I have some static resources (images and HTML files) that will be localized. One
I know that i have to dispose all unmanaged resources in a class or
We have an app that needs to access network resources. It's written in VB.Net.
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have an application that differs for different languages by resources. Is there a

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.