On Apr 20, 4:09 pm, darren <backdoc...@gmail.com> wrote:
> I am not able to figure out how to order the records that fill the
> drop down list in a model form.  On line 112 below, I have attempted
> to order the Rotation model by player.  But, the drop down list that
> is created for me is not ordered that way.  I also tried relocating
> line 112 to within the Meta class definition.  But, that didn't work
> either.  I see field ordering in the docs.  But, I don't see this
> mentioned.
>
> Any suggestions would be more than appreciated.
>
> 101 class Rotation(models.Model):
> 102     player = models.ForeignKey(Person, to_field='f_name',
> verbose_name='Player', limit_choices_to={'relationship' : 'Player'})
> 103     date = models.DateField('Date', default=datetime.date.today)
> 104     game_type = models.CharField("Game Type",
> choices=(('Scrimmage', 'Scrimmage'), ('Tournament', 'Tournament')),
> max_length=10)
> 105     inning_count = models.IntegerField("Innings Out", default=1)
> 106     def __unicode__(self):
> 107         return '%s || %s %s || %s || %s' % (self.date,
> self.player.f_name, self.player.l_name, self.game_type,
> str(self.inning_count))
> 108     class Meta:
> 109         ordering = ['date']
> 110
> 111 class RotationForm(forms.ModelForm):
> 112     Rotation.objects.order_by('player')
> 113     class Meta:
> 114         model = Rotation
> 115         exclude = ['date', 'inning_count']

You can add an 'ordering' property to your Rotation model's Meta
class:
class Meta:
  ordering = ['player']
The order will then be the same as the order specified in the Player
model.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to