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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:50:49+00:00 2026-05-20T00:50:49+00:00

I have a model AccountImport that very clearly has a foreign key to GenericImport

  • 0

I have a model AccountImport that very clearly has a foreign key to GenericImport:

from django.db import models
from mcif.models.generic_import import GenericImport

class AccountImport(models.Model):

    id = models.BigIntegerField(primary_key=True)
    generic_import = models.ForeignKey(GenericImport)
    is_entirely_international = models.IntegerField()
    is_queued = models.IntegerField()
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()

    class Meta:
        db_table = u'account_import'
        app_name = 'mcif'

And here’s GenericImport:

from django.db import models
from mcif.models.import_profile import ImportProfile
from mcif.models.import_file import ImportFile
from mcif.models.import_bundle import ImportBundle
from mcif.models.customer import Customer
from mcif.models.csv_row import CSVRow
import csv, cStringIO

class GenericImport(models.Model):

    class Meta:
        db_table = u'generic_import'
        app_name = 'mcif'

    id = models.BigIntegerField(primary_key=True)
    import_profile = models.ForeignKey(ImportProfile)
    import_file = models.ForeignKey(ImportFile)
    notes = models.TextField()
    start_time = models.DateTimeField()
    end_time = models.DateTimeField()
    active = models.IntegerField()
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()
    unsavable_rows = models.TextField()
    import_bundle = models.ForeignKey(ImportBundle)
    is_queued = models.IntegerField()

    @classmethod
    def last(cls):
        all = GenericImport.objects.all()
        return all[len(all) - 1]

    def process(self):
        for line in self.import_file.file.split("\n")[:30]:
            f = cStringIO.StringIO(line)
            row = CSVRow()
            row.array = next(csv.reader(f))
            row.generic_import = self
            row.process()
            f.close()

But watch what happens when I do this:

>>> from mcif.models.generic_import import GenericImport
>>> GenericImport.objects.all()[0].account_import_set.all()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'GenericImport' object has no attribute 'account_import_set'

Isn’t that supposed to work? I don’t understand what I could have done 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-05-20T00:50:49+00:00Added an answer on May 20, 2026 at 12:50 am

    It should be your model name in lowercase unless overriden by related_name.
    http://docs.djangoproject.com/en/dev/topics/db/queries/#following-relationships-backward

    GenericImport.objects.latest('id').accountimport_set.all()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model with a Foreign Key to itself like this: class Concept(models.Model): name
I have model Article it has field title with some text that may contain
I have a situation where I have Model A that has a variety of
I have a Django model where I'm importing a number of items: from django.db
I wrote a certain function that I'd like all my Django models to have.
I have model data that came from a MultipleChoiceField. I have figured out it
we have model helper (used by several different models) called set_guids that sets self.theguid
How can i have model in knockoutjs that gets its data from an sqlite
I have model Foo which has field bar. The bar field should be unique,
In my controller I have model operations that can return empty results. I've setup

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.