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

  • Home
  • SEARCH
  • 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 9175899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:59:32+00:00 2026-06-17T16:59:32+00:00

I have a model like this in Django: class File(models.Model): users = models.ForeignKey(User) file_name

  • 0

I have a model like this in Django:

class File(models.Model):
    users = models.ForeignKey(User)
    file_name = models.CharField(max_length=100)
    type = models.CharField(max_length=10)
    source = models.CharField(max_length=100)
    start_date = models.TextField()
    end_date = models.TextField()
    duration = models.TextField()
    size = models.TextField()
    flag = models.TextField()
    #delete_date = models.CharField(max_length=100, null=True, blank=True)

class Share(models.Model):
    users = models.ForeignKey(User)
    files = models.ForeignKey(File)
    shared_user_id = models.IntegerField()
    shared_date = models.TextField()

I am trying to extract the file shared by logged in user. I simply query in Share

file_s = Share.objects.filter(users_id=log_id)

This extracts the file shared by logged in user. Since, now I know which file is shared by logged in user I tried to get the file information from file table:

shared_file = File.objects.filter(users_id=file_s)

But this is returning:

DatabaseError at /shared_by_me/
(1242, 'Subquery returns more than 1 row')

#my_views
def shared_by_me(request):
    log_id = request.user.id
    username = request.user.username
    #shared_file = File.objects.filter(users_id=file)
    file_s = Share.objects.filter(users_id=log_id)
    shared_file = File.objects.filter(users_id=file_s)
    #b = Share.objects.filter(users_id=log_id)
    return render_to_response('shared_by_me.html', {'shared_by_me':shared_file, 'username':username}, context_instance=RequestContext(request))

#my_template
{% for choice in shared_by_me %}
            <tr class="oddclass">
              <td><input type="checkbox" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" /></td>
              <td><label for="choice{{ forloop.counter }}">{{ choice.file_name }}</label></td>
              <td>{{ choice.type }}</td>
              <td>{{ i.size }}</td>
              <td>{{ i.end_date }}</td>
            </tr>
{% endfor %}

What am I doing wrong?

  • 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-17T16:59:33+00:00Added an answer on June 17, 2026 at 4:59 pm

    Because file is not a model but a queryset you should use __in, something like:

    shared_file = File.objects.filter(users_id__in=file_s)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two simple models like this: class User(models.Model): username = models.CharField(max_length=100) #Id
I have model like this: class File(models.Model): name = models.CharField(max_length=45) description = models.CharField(max_length=100, blank=True)
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a model like this: class Item(models.Model): code = models.CharField(max_length=200, unique=True) barcode =
I have two models in my Django app file models.py like so: class User(models.Model):
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I have a django model like this: class Something(models.Model): attr1 = models.IntegerField() attr2 =
i've a problem with my tabularinline field. I have model like this class Product(models.Model):
I have a model like this: class Users(db.Model): email = db.EmailProperty(required=True, indexed=True) user_name =
I have a simple model like this: class User < ActiveRecord::Base serialize :preferences end

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.