I'm (still) working on my computer museum site,

I originally set-up Systems and Images in the database like this:

class System(models.Model):
        manufacturer = models.ForeignKey('Manufacturer')
        name = models.CharField(max_length=80)
        slug = models.CharField(max_length=80)
        systemType = models.ForeignKey('Classification')
<cut for brevity>
        info = models.TextField()
        system_pictures = models.ManyToManyField('Image')
        public = models.BooleanField()

        def __unicode__(self):
            return self.name

        def get_header_pic(self):
            return self.system_pictures.filter
(image_category__name='Header_Pic')[0]

        def get_header_logo(self):
            return self.system_pictures.filter
(image_category__name='Header_Logo')[0]

class Image(models.Model):
        name = models.CharField(max_length=80)
        location = models.URLField()
        height = models.IntegerField()
        width = models.IntegerField()
        image_category = models.ForeignKey('ImageCat')
        info = models.TextField()
        primary = models.BooleanField()

        def __unicode__(self):
            return self.name

The Idea was to be able to access all related images to a given system
through, System.image and image_category.

I constantly get interrupted in the development of this, as I'm doing
it on my own time and have 2 kids. :)

When I got the the Magazine articles section, I realized I needed
thumb nail images. Not seeing another way to do it, I added this:

class Thumb(models.Model):
    name = models.CharField(max_length=80)
    location = models.URLField()
    height = models.IntegerField()
    width = models.IntegerField()
    image_category = models.ForeignKey('ImageCat')
    big = models.ForeignKey('Image')
    primary = models.BooleanField()

Now, as magazine articles may relate to more that one system, I added
this for Magazines:

class MagPublisher(models.Model):
    name = models.CharField(max_length=80)

    def __unicode__(self):
            return self.name

class Magazine(models.Model):
    article = models.CharField(max_length=80)
    slug = models.CharField(max_length=80)
    date = models.CharField(max_length=40)
    system = models.ManyToManyField('System')
    publisher = models.ForeignKey('MagPublisher')
    imagesmall = models.ManyToManyField('Thumb')
    pdf_location = models.URLField(blank=True,null=True)

    def __unicode__(self):
        return self.article

    def get_thumb(self):
        return self.imagesmall.filter(primary=True)[0]

This all works fine as it is, but now I'm attempting to make the
system image pages and screen shot pages.

Here is the Question/Problem,

I find myself duplicating the Magazine structure rather than accessing
the images through the System, as I can't see how I could at this
point.

class UnitPic(models.Model):
    name = models.CharField(max_length=80)
    slug = models.CharField(max_length=80)
    system = models.ManyToManyField('System')
    imagesmall = models.ManyToManyField('Thumb')

    def __unicode__(self):
        return self.name

    def get_thumb(self):
        return self.imagesmall.filter(primary=True)[0]

class ScreenPic(models.Model):
    name = models.CharField(max_length=80)
    slug = models.CharField(max_length=80)
    system = models.ManyToManyField('System')
    imagesmall = models.ManyToManyField('Thumb')

    def __unicode__(self):
        return self.name

    def get_thumb(self):
        return self.imagesmall.filter(primary=True)[0]

Should I continue this way or should (how could ) I re-work the
System, Image and Thumb models to do the job?

I'm thinking I need another descriptor on the Image model.

Oh, 'primary' marks the Image I want to pull If I only want 1 out of
the set.

Lance F. Squire

P.S. I have the Practical Django Projects book, but it dosn't seem
very useful since the 1.0 version came out. :(
--~--~---------~--~----~------------~-------~--~----~
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 
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