Thank you Eric for the pointers!
But I think Django is complaining about me having too many Relationships in
table Altword, or perhaps I have typed syntax wrong and missunderstand the
error message?
Exception Value:
<class 'navi_polls.models.Altword'> has more than 1 ForeignKey to <class
'navi_polls.models.Word'>
#_______________________________________________________________________________
class Word(models.Model):
rosword = models.CharField(max_length=200)
direct_transl_word = models.CharField(max_length=120, blank=True,
null=True)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.rosword
#_______________________________________________________________________________
class Altword(models.Model):
#class Altword(Word):
rosword = models.*ForeignKey*(Word)
alt_ros_word = models.CharField(max_length=200)
alt_transl_word = models.CharField(max_length=200)
articulate = models.CharField(max_length=200)
wordy = models.*OneToOneField*(Word, related_name='altword_wordy',
primary_key=True)
votes = models.IntegerField(default=0)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.alt_ros_word
#_______________________________________________________________________________
First I tried to follow this example but then above error showed up:
https://docs.djangoproject.com/en/1.5/topics/db/examples/one_to_one/
Second time I tried this but I couldn't make it work:
http://catherinetenajeros.blogspot.se/2013/04/django-error-one-or-more-models-did-not.html
Third time I tried to play with "Multi-table inheritance". But it only
lead to Django complaining about duplicate fields which suggested that I
needed to change field names in several files. I didn't go down that path.
And it seemed "Multi-table inheritance" also complained about my first
error message about having too many relationships in Altword table.
https://docs.djangoproject.com/en/1.0/topics/db/models/#id7
How should I proceed in order to find the solution to this problem?
On Saturday, August 10, 2013 10:32:37 AM UTC+2, Eric Cheung wrote:
>
> 1) The model Word does not have the votes field, you cannot order the
> field it's not possessed.
>
> 2) You have to build a relation between the models first, check the
> relationships from Django Doc
> https://docs.djangoproject.com/en/dev/topics/db/models/#relationships
>
> On Friday, August 9, 2013 10:04:47 PM UTC+8, Pepsodent Cola wrote:
>>
>> 1.)
>> How can I order my list based on a field in a different table?
>>
>> return Word.objects.filter(direct_transl_word='')
>>
>> The above I want to do something like this where the field ('-votes') is
>> located at table Altword.
>> Nothing happens when I use this though, don't understand why?
>>
>> #return
>> Word.objects.filter(direct_transl_word='').order_by('-votes')
>>
>>
>> 2.)
>> My *altword_list.html* viewpage breaks whenever I try to use query for
>> my other table Altword.
>>
>> #return Altword.objects.filter(rosword__direct_transl_word='')
>> #return Altword.objects.filter(word__direct_transl_word='')
>>
>> #_______________________________________________________________________________
>>
>> *AltwordlistView*
>> class AltwordlistView(generic.DetailView):
>> model = Word
>> #model = Altword
>> template_name = 'navi_polls/altword_list.html'
>> context_object_name = 'poll'
>>
>> def get_queryset(self):
>> # Filter 5
>> return Word.objects.filter(direct_transl_word='')
>> #return
>> Word.objects.filter(direct_transl_word='').order_by('-votes')
>> #return Altword.objects.filter(rosword__direct_transl_word='')
>> #return Altword.objects.filter(word__direct_transl_word='')
>>
>> #_______________________________________________________________________________
>>
>> *Models*
>> class Word(models.Model):
>> rosword = models.CharField(max_length=200)
>> direct_transl_word = models.CharField(max_length=120, blank=True,
>> null=True)
>> pub_date = models.DateTimeField('date published')
>>
>> def __unicode__(self):
>> return self.rosword
>>
>> #_______________________________________________________________________________
>>
>> *Models*
>> class Altword(models.Model):
>> rosword = models.ForeignKey(Word)
>> alt_ros_word = models.CharField(max_length=200)
>> alt_transl_word = models.CharField(max_length=200)
>> articulate = models.CharField(max_length=200)
>> *votes* = models.IntegerField(default=0)
>> pub_date = models.DateTimeField('date published')
>>
>> def __unicode__(self):
>> return self.alt_ros_word
>>
>>
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.