First off all I want to thank you all for this excellent web
framework.  I had never built a database driven web site, but Django
has given me the motivation to create a small intranet site for our
office and I am very happy with the progress I have been able to make
so far.  I realize that it is still in heavy design/development so I
am prepared to be patient with some features.  I do have a couple of
quick questions though.

I have a model for our personnel/contacts that look like this:

class Contact(models.Model):
    first = models.CharField(maxlength=30)
    last = models.CharField(maxlength=30)
    login_name = models.CharField(maxlength=15, blank=True)
    is_staff = models.BooleanField()
    etc...

    def __str__(self):
        return '%s %s' % (self.first, self.last)

    class Admin:
        list_display = ('first', 'last', 'phone', 'email', 'company',)
        ordering       = ('first','last')

I am trying to create an application that will allow users to post
when they are going to be out of the office.  So, after creating the
app, I created a model that looks like this:

class away(models.Model):
    contact = models.ForeignKey(Contact, verbose_name="Name of person
away", limit_choices_to= {'is_staff':True}, db_column='contact')
    out_time = models.DateTimeField()
    return_time = models.DateTimeField()
    comments = models.TextField(maxlength=3000, blank=True)

    def __str__(self):
        return '%s' % (self.contact,)

    class Admin:
        list_display = ('contact', 'out_time', 'return_time',
'location_reason', 'comments',)
        list_filter    = ('out_time', 'return_time',)
        ordering       = ('out_time','return_time',)
        search_fields  = ('contact',)

It actually works!  In the admin interface it displays the 'contact'
field as a combination of the 'first' and 'last' fields of the
contact, which is exactly what I wanted.  But, my question is how did
it know to do that?  What if I had wanted it to display the
'login_name' instead, for instance?

The second question is related to the same field.  In the create new
'Away' form, the contact field is shown as a select field, which is
great, but the items in it are not sorted.  They are placed in the
order in which they are created.  Is there a way to sort the items on
that list?


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

Reply via email to