Lance,

Regarding the many to many field that shows too many images:

I've used this project with some success in the past:
http://code.google.com/p/django-ajax-filtered-fields/
They allow you to setup some ajax filtering for the field, which can
make it a lot easier to find what you are looking for.
Also, if you can think of a way to make it work, there is a
limit_choices_to kwarg that you can use to cut down on all the
choices.

As far as combining the fields, if they are really are different
objects, I wouldn't combine them. You want to combine them because
they have lots of fields that are the same, not because they are the
same object. I'd say you should just make an abstract base model class
and have them both inherit from it. That way you don't have repeated
code, but you aren't forcing data into a place it doesn't fit. On the
other hand, if they really are the same kind of thing, then adding a
couple fields makes sense.

Hope that helps,
Alex

On Sep 7, 8:13 pm, "Lance F. Squire" <la...@alteeve.com> wrote:
> Ok, I'm just getting back to a project I had to put on hold for a
> while.
>
> I recently read an article on problems new Django users fall into, and
> I think I hit one.
>
> The bottom of my 'Systems' model looks like this:
>
>         keyboard = models.CharField(max_length=80)
>         cart = models.CharField(max_length=80)
>         ram = models.CharField(max_length=40)
>         rom = models.CharField(max_length=40)
>         media = models.CharField(max_length=80)
>         options = models.CharField(max_length=120)
>         quick = models.TextField()
>         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]
>
> The problem is that when using the admin to enter the data for the
> Systems, I get a list of every pic in the 'Image' model to choose
> from.
>
> I can see this getting frustrating very fast.
>
> I'm thinking that I can just use the fields in the 'Image' model to
> find the appropriate pics, but don't know how to re-structure
> 'get_header_pic' to work with that. Or should I be doing something
> different in the View or Template to access these pics?
>
> Also, I added and 'Thumb' model when I added functionality I hadn't
> originally though of. Unfortunately, it's almost an exact copy of the
> "Image' model I made.
>
> As seen here:
>
> class Image(models.Model):
>         name = models.CharField(max_length=80)
>         slug = 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
>
> class Thumb(models.Model):
>     name = models.CharField(max_length=80)
>     slug = models.CharField(max_length=80)
>     location = models.URLField()
>     height = models.IntegerField()
>     width = models.IntegerField()
>     system = models.ForeignKey('System')
>     image_category = models.ForeignKey('ImageCat')
>     big = models.ForeignKey('Image')
>     primary = models.BooleanField()
>
>     def __unicode__(self):
>         return self.name
>
> I'm thinking I should merge them by adding t_height, t_width and
> t_location to the 'Image' model. Am I missing any downside to doing
> this?
>
> Lance

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