Thanks Malcolm,
Link number 2 is great and I feel like I got real close.

======== Reason ========

The reason I am doing this:
1) this isn't just for weekdays, I am planning on using this for most
of my array/dictionaries
2) Also, I like to give the stuff more control over the site via the
admin interface.

I have contributed my code and probably more interesting to you my
data as open source in the hope that it will be helpful to you and
others. I think if you take look at the code and data you will
understand why I need this.
http://code.google.com/p/django-tamer/

======== The Challenge ========

I have two more problems
1) In the dictionary how do I pass the value weekday as a variable to
the sql?
2) How do I format  the line "p = self.model(row[0], row[1])" to get
the right format for choices?

======== CODE ========

class DictManager(models.Manager):
    def with_counts(self):
        from django.db import connection
        cursor = connection.cursor()
        cursor.execute("""
           SELECT id, value
           FROM data_data
           WHERE group = 'weekday'
           ORDER BY id
           """)
        result_list = []
        for row in cursor.fetchall():
            p = self.model(row[0], row[1])
            result_list.append(p)
        return result_list

class Dict(models.Model):
    group    = models.CharField(maxlength=10, verbose_name=_('Group'))
    value   = models.CharField(maxlength=30, verbose_name=_('Value'))

    objects = models.Manager()
    dictionary = DictManager()

    class Meta:
                verbose_name = _('Dictionary')
                verbose_name_plural = _('Dictionaries')

    class Admin:
                list_display = ('id', 'group', 'value')
                search_fields = ['group', 'value']

    def __str__(self):
                return self.dictionary

class Route(models.Model):
       weekdays  = models.ManyToManyField(Dict)


--~--~---------~--~----~------------~-------~--~----~
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