I have a form where I need to display 2 fields in one select box, with
one field left justified and one field right justified.

Here is the model:

class Group(models.Model):
    ordering = ['order',]

    GROUP_BY_CHOICES = (
        ("Target", "Target"),
        ("Recipe", "Recipe"),
        ("PPL", "PPL"),
        ("Lot", "Lot"),
    )

    name = models.CharField(max_length=25, unique=True)
    order = models.IntegerField(default=0)
    prefixes = models.TextField()
    group_by = models.CharField(max_length=25,
choices=GROUP_BY_CHOICES, default="Target", null=True)

    def __unicode__(self):
        from django.utils.safestring import mark_safe
        import re

        b = '%-08s %s' % (self.name, self.group_by)
        return mark_safe(re.sub('\s', '&'+'nbsp;', b))


Here is the form widget:

class GroupModelChoiceField(forms.ModelChoiceField):
    def __init__(self, **kwargs):
        super(GroupModelChoiceField, self).__init__(
            Group.objects.all(), required=False, empty_label="",
            **kwargs)

I tried to create the justification by adding spaces, but since the
font is not monospaced, that doesn't work (the client doesn't want a
monospaced font anyway).

Then I tried returning some embedded CSS like this:

        return mark_safe('<div style="float: left">%s</div><div
style="float: right">%s</div>' % (self.name, self.group_by))

But all the HTML gets srtipped out and I end out with just the 2
fields running together. Is there some way to achieve this?

Also, the select box is not wide enough to hold the 2 fields, so the
second one is getting truncated on the right. How can I make it
longer?

And, finally, in my admin page for this model:

class GroupAdmin(admin.ModelAdmin):
    radio_fields = {"group_by": admin.HORIZONTAL}
    list_display = ('name', 'order', 'prefixes', 'group_by')
admin.site.register(Group, GroupAdmin)

It is not sorting by the order column, even though I have:

    ordering = ['order',]

in the model definition. I thought that was all that was needed to
specify a sort order. What am I missing here?

TIA!
-larry

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY5r1Le7UbcrLXHSJs-eodST0hEMD-ZAOa5GWHwJeCPABg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to