miratcan / qhonuskan-votes

Simple reddit like voting system without usage off GenericForeignKeys. Built for linkfloyd project.
Other
30 stars 11 forks source link

AttributeError: type object 'Thing' has no attribute 'objects' #8

Closed nickb4 closed 4 years ago

nickb4 commented 12 years ago

Hi,

I believe that I have configured my project according to your tutorial and demo project, but I am encountering an error:

AttributeError: type object 'Thing' has no attribute 'objects'

which references a call in my view to:

Thing.objects.all()

This error only occurs when the qhonuskan_votes 'VotesField' and 'ObjectsWithScoresManager' fields are included in my model Thing:

class Thing(models.Model):
    user = models.ForeignKey(User)
    color = models.CharField(max_length=5, choices=COLORS)
    photo = models.ImageField(upload_to='photos')
    make = models.ForeignKey('Make')
    additional_description = models.TextField(default='')
    price = models.DecimalField(max_digits=10, decimal_places=2, default=Decimal('0.00'))
    votes = VotesField()
    objects_with_scores = ObjectsWithScoresManager()

    def __unicode__(self):
        return unicode(self.user)

@receiver(vote_changed)
def my_callback(sender, dispatch_uid="vote_changed", **kwargs):
    print "vote_changed signal fired."

I believe that I set up my template properly, as well:

{% extends 'base.html' %}
{% load qhonuskan_votes static %}
{% get_static_prefix as STATIC_PREFIX %}

<head>
<link href="{{STATIC_PREFIX}}default_buttons.css" rel="stylesheet" type="text/css" />
<style type="text/css">
div.vote_buttons {
   width: 40px;
   margin-right: 5px;
   float: left;
   border: 1px solid #666;
 }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
{% voting_script %}
</head>

{% for thing in things %}
<div class="object">
    {% vote_buttons_for thing %}
      <div class="text">
        {{ thing.additional_description }}
      </div>
</div>
{% endfor %}

In the view I am trying to call Thing.objects.all() to use in a different part of the template, but including the VotesField and ObjectsWithScoresManager in my model for Thing results in the AttributeError described above.

Am I doing something wrong in my use of the app? Perhaps, do I need to create a separate model Vote Then reference its relation to Thing by using a FK?

Thanks for any clarification on this issue!

alejandronanez commented 12 years ago

Hi.

I had the same problem. In your view you need to do Thing.objects_with_scores.all() to make it work.

Hope it helps,

miratcan commented 12 years ago

actually, it happens on me too, but i couldn't realize why it does :o) i'm open for any suggestions about that issue.

miratcan commented 11 years ago

We have to add objects before all other managers to avoid issues mention in http://stackoverflow.com/a/4455374/1462141

Try like this:

class MyModel(models.Model):
    votes = VotesField()
    objects = models.Manager()
    objects_with_scores = ObjectsWithScoresManager()

(Step 2 at README.rst is updated with that information)