Also, I think you need to add null=True to the ForeignKey, like this: category = models.ForeignKey(Category,null=True, blank=True)
blank=True indicates the admin interface that a value can be omitted, but null=True is necessary to indicate to the database that the column can be NULL. On 7/12/06, Phil Powell <[EMAIL PROTECTED]> wrote: > > Hi - I've got a bit of a conundrum. > > I have two models, Category and Photo which look something like this: > > class Category(models.Model): > title = models.CharField(maxlength=80) > slug = models.SlugField(prepopulate_from=("title",)) > > class Photo(models.Model): > catalogue_number = models.IntegerField(maxlength=80) > slug = models.SlugField(prepopulate_from=("catalogue_number",)) > category = models.ForeignKey(Category,blank=True) > > There is a one-to-many relationship defined so that a Photo can be > assigned a Category. > > Now, what I want to be able to do is get a list of Categories, but > ONLY those Categories which have been assigned to one or more Photos. > > I can think of plenty of ugly ways to work around this, but wondered > whether anyone had a graceful solution? > > -Phil > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---