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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:26:21+00:00 2026-06-12T03:26:21+00:00

This is my models.py: from tastypie.utils.timezone import now from django.contrib.auth.models import User from django.db

  • 0

This is my models.py:

from tastypie.utils.timezone import now
from django.contrib.auth.models import User
from django.db import models
from django.template.defaultfilters import slugify


class Link(models.Model):
    user = models.ForeignKey(User)
    pub_date = models.DateTimeField(default=now)
    title = models.CharField(max_length=200)
    slug = models.SlugField()
    body = models.TextField()


    def __unicode__(self):
        return self.title

    def save(self, *args, **kwargs):
        # For automatic slug generation.
        if not self.slug:
            self.slug = slugify(self.title)[:50]

        return super(Link, self).save(*args, **kwargs)

class OAuthConsumer(models.Model):

    name = models.CharField(max_length=255)
    key = models.CharField(max_length=255)
    secret = models.CharField(max_length=255)
    active = models.BooleanField(default=True)

    class Meta:
        db_table = "api_oauth_consumer"


    def __unicode__(self):
         return u'%s' % (self.name)

Everything works now and I get this as response to: /api/v1/links/list/?format=json

{
    "meta": {
        "previous": null, 
        "total_count": 1, 
        "offset": 0, 
        "limit": 20, 
        "next": null
    }, 
    "objects": [
        {
            "body": "http://www.youtube.com/watch?v=wqQ6BF50AT4&feature=relmfu", 
            "title": "Youtube", 
            "slug": "main-kya-karoon", 
            "user": "/api/v1/users/1/", 
            "pub_date": "2012-10-01T00:23:53", 
            "id": 1
        }
    ]
}

I want to make these changes:

  1. Pass the username and get all the links belonging to that username.
  2. I am currently adding content and creating new user via django admin as while doing post I always manage to get an error. I think I might have gone wrong so any help maybe a curl one liner of creating a new user using my current api would be helpful.

Edit:

This is my new api.py(I decided to create a new UserSignUpResource):

# myapp/api.py

from django.contrib.auth.models import User
from tastypie.authorization import Authorization
from tastypie import fields
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
from links.models import Link
from tastypie.serializers import Serializer
from tastypie.admin import ApiKeyInline
from tastypie.models import ApiAccess, ApiKey
from django.db import models
from tastypie.authentication import ApiKeyAuthentication
from tastypie.models import create_api_key
class UserResource(ModelResource):

    class Meta:
        queryset = User.objects.all()
        resource_name = 'users'
        excludes = ['email', 'password', 'is_active', 'is_staff', 'is_superuser'] 
        authorization = Authorization()
        allowed_methods = ['post','get']
        fields = ['username']

        def obj_create(self, bundle, request=None, **kwargs):
            try:
                bundle = super(CreateUserResource, self).obj_create(bundle, request, **kwargs)
                bundle.obj.set_password(bundle.data.get('password'))
                bundle.obj.set_username(bundle.data.get('username'))
                bundle.obj.save() 
            except IntegrityError:
                raise BadRequest('That username already exists')
            return bundle

class LinkResource(ModelResource):
    user = fields.ForeignKey(UserResource, 'user')
    authorization = Authorization()
    class Meta:
        queryset = Link.objects.all()
        resource_name = 'links/list'
        excludes = ['id']
        authorization = Authorization()
        include_resource_uri = False
        excludes = ['limit']

    def apply_filters(self,request,applicable_filters):
        base_object_list = super(LinkResource, self).apply_filters(request, applicable_filters)

        query = request.META.get('HTTP_AUHTORIZATION')
        if query:
            qset = (
                Q(api_key=query))
            base_object_list = base_object_list.filter(qset).distinct()

            return base_object_list

class UserSignUpResource(ModelResource):

    class Meta:
        object_class = User
        queryset = User.objects.all()
        allowed_methods = ['post']
        include_resource_uri = False
        resource_name = 'newuser'
        excludes = ['is_active','is_staff','is_superuser']
        authentication = ApiKeyAuthentication()
        authorizaton = Authorization()
        models.signals.post_save.connect(create_api_key, sender=User)

    def obj_create(self,bundle,request=None,**kwargs):
        try:
            bundle = super(UserSignUpResource, self).obj_create(bundle,request,**kwargs)
            bundle.obj.set_password(bundle.data.get('password'))
            bundle.obj.save()
        except IntegrityError:
            raise BadRequest('The username already exists')
        return bundle

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

Now when I do this:

curl -v -X POST -d '{"username" : "puck", "password" : "123456"}' -H "Authorization: ApiKey superusername:linklist" -H "Content-Type: application/json" http://127.0.0.1:8000/api/v1/newuser

I get this a 404 error: The url doesn’t exist. I checked and rechecked and I don’t see any problem with the url.

Edit:
It was a rather dumb mistake on my part. I had forgotten to register the UserSignUpResource in urls.py.

  • 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-12T03:26:22+00:00Added an answer on June 12, 2026 at 3:26 am

    1. Pass the username and get all the links belonging to that username

    Look at filtering resources based on the api call in tastypie as explained in passing request variables in django/tastypie resources

    For creating user see How to create or register User using django-tastypie API programmatically?

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

Sidebar

Related Questions

This is my api.py # myapp/api.py from django.contrib.auth.models import User from tastypie.authorization import Authorization
name 'entry_resource' is not defined This is my models.py from tastypie.utils.timezone import now from
Given this model: from django.db import models from django.contrib.auth.admin import User # Create your
from django.contrib.auth.models import User u = User.objects.get(username='test') user.password u'sha1$c6755$66fc32b05c2be8acc9f75eac3d87d3a88f513802 Is reversing this password encryption
I have a model that looks like this: from django.db import models from django.contrib.auth.models
I had a many-to-many relationship between two Django Models: from django.contrib.auth.models import User class
Initially, I started my UserProfile like this: from django.db import models from django.contrib.auth.models import
Consider the following django model from django.db import models from django.contrib import auth class
I inherited form the django user model like so: from django.db import models from
This is my models.py from django.db import models class School(models.Model): school = models.CharField(max_length=300) def

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.